Skip to content
This repository was archived by the owner on Sep 28, 2020. It is now read-only.

Commit c5d6157

Browse files
committed
Adding small amount of unit tests for DownloadUrlResolver.
1 parent 6c160f1 commit c5d6157

File tree

5 files changed

+174
-4
lines changed

5 files changed

+174
-4
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using NUnit.Framework;
6+
using YoutubeExtractor;
7+
8+
namespace YoutubeExtractor.Tests
9+
{
10+
/// <summary>
11+
/// Small series of unit tests for DownloadUrlResolver. Run these with NUnit.
12+
/// </summary>
13+
[TestFixture]
14+
public class DownloadUrlResolverTest
15+
{
16+
[Test]
17+
public void TryNormalizedUrlForStandardYouTubeUrlShouldReturnSame()
18+
{
19+
string url = "http://youtube.com/watch?v=12345";
20+
21+
string normalizedUrl = String.Empty;
22+
23+
Assert.IsTrue(DownloadUrlResolver.TryNormalizeYoutubeUrl(url, out normalizedUrl));
24+
Assert.AreEqual(url, normalizedUrl);
25+
}
26+
27+
[Test]
28+
public void TryNormalizedrlForYouTuDotBeUrlShouldReturnNormalizedUrl()
29+
{
30+
string url = "http://youtu.be/12345";
31+
32+
string normalizedUrl = String.Empty;
33+
Assert.IsTrue(DownloadUrlResolver.TryNormalizeYoutubeUrl(url, out normalizedUrl));
34+
Assert.AreEqual("http://youtube.com/watch?v=12345", normalizedUrl);
35+
}
36+
37+
[Test]
38+
public void TryNormalizedUrlForMobileLinkShouldReturnNormalizedUrl()
39+
{
40+
string url = "http://m.youtube.com/?v=12345";
41+
42+
string normalizedUrl = String.Empty;
43+
Assert.IsTrue(DownloadUrlResolver.TryNormalizeYoutubeUrl(url, out normalizedUrl));
44+
45+
Assert.AreEqual("http://youtube.com/watch?v=12345", normalizedUrl);
46+
}
47+
48+
[Test]
49+
public void GetNormalizedYouTubeUrlForBadLinkShouldReturnNull()
50+
{
51+
string url = "http://notAYouTubeUrl.com";
52+
53+
string normalizedUrl = String.Empty;
54+
Assert.IsFalse(DownloadUrlResolver.TryNormalizeYoutubeUrl(url, out normalizedUrl));
55+
Assert.IsNull(normalizedUrl);
56+
}
57+
}
58+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("YoutubeExtractor.Tests")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("YoutubeExtractor.Tests")]
13+
[assembly: AssemblyCopyright("Copyright © 2014")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("d3dc4895-ef34-4c2f-b2b1-5b9ff8b5635d")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{CE76B74C-BD0C-4768-8F8B-78E0FBD46FBC}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>YoutubeExtractor.Tests</RootNamespace>
11+
<AssemblyName>YoutubeExtractor.Tests</AssemblyName>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<TargetFrameworkProfile />
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<DebugType>pdbonly</DebugType>
27+
<Optimize>true</Optimize>
28+
<OutputPath>bin\Release\</OutputPath>
29+
<DefineConstants>TRACE</DefineConstants>
30+
<ErrorReport>prompt</ErrorReport>
31+
<WarningLevel>4</WarningLevel>
32+
</PropertyGroup>
33+
<ItemGroup>
34+
<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
35+
<SpecificVersion>False</SpecificVersion>
36+
<HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
37+
</Reference>
38+
<Reference Include="System" />
39+
<Reference Include="System.Core" />
40+
<Reference Include="System.Xml.Linq" />
41+
<Reference Include="System.Data.DataSetExtensions" />
42+
<Reference Include="System.Data" />
43+
<Reference Include="System.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="DownloadUrlResolverTest.cs" />
47+
<Compile Include="Properties\AssemblyInfo.cs" />
48+
</ItemGroup>
49+
<ItemGroup>
50+
<None Include="packages.config" />
51+
</ItemGroup>
52+
<ItemGroup>
53+
<ProjectReference Include="..\YoutubeExtractor\YoutubeExtractor.csproj">
54+
<Project>{ecdc127f-8def-4f99-8300-72c13597339d}</Project>
55+
<Name>YoutubeExtractor</Name>
56+
</ProjectReference>
57+
</ItemGroup>
58+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
59+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
60+
Other similar extension points exist, see Microsoft.Common.targets.
61+
<Target Name="BeforeBuild">
62+
</Target>
63+
<Target Name="AfterBuild">
64+
</Target>
65+
-->
66+
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="NUnit" version="2.6.3" targetFramework="net35" />
4+
</packages>

YoutubeExtractor/YoutubeExtractor.sln

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 2013
4-
VisualStudioVersion = 12.0.30110.0
4+
VisualStudioVersion = 12.0.30501.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YoutubeExtractor", "YoutubeExtractor\YoutubeExtractor.csproj", "{ECDC127F-8DEF-4F99-8300-72C13597339D}"
77
EndProject
@@ -19,10 +19,9 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleApplication.Portable
1919
{1BB4CF4D-3617-4A23-B51A-DA7711E6F8EB} = {1BB4CF4D-3617-4A23-B51A-DA7711E6F8EB}
2020
EndProjectSection
2121
EndProject
22+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YoutubeExtractor.Tests", "YoutubeExtractor.Tests\YoutubeExtractor.Tests.csproj", "{CE76B74C-BD0C-4768-8F8B-78E0FBD46FBC}"
23+
EndProject
2224
Global
23-
GlobalSection(CodealikeProperties) = postSolution
24-
SolutionGuid = 09b3acc1-9c76-4060-a18f-5b5f253925cc
25-
EndGlobalSection
2625
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2726
Debug|Any CPU = Debug|Any CPU
2827
Release|Any CPU = Release|Any CPU
@@ -45,8 +44,15 @@ Global
4544
{D71C979F-7F55-4AD3-854C-7F1FFF35B4F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
4645
{D71C979F-7F55-4AD3-854C-7F1FFF35B4F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
4746
{D71C979F-7F55-4AD3-854C-7F1FFF35B4F0}.Release|Any CPU.Build.0 = Release|Any CPU
47+
{CE76B74C-BD0C-4768-8F8B-78E0FBD46FBC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
48+
{CE76B74C-BD0C-4768-8F8B-78E0FBD46FBC}.Debug|Any CPU.Build.0 = Debug|Any CPU
49+
{CE76B74C-BD0C-4768-8F8B-78E0FBD46FBC}.Release|Any CPU.ActiveCfg = Release|Any CPU
50+
{CE76B74C-BD0C-4768-8F8B-78E0FBD46FBC}.Release|Any CPU.Build.0 = Release|Any CPU
4851
EndGlobalSection
4952
GlobalSection(SolutionProperties) = preSolution
5053
HideSolutionNode = FALSE
5154
EndGlobalSection
55+
GlobalSection(CodealikeProperties) = postSolution
56+
SolutionGuid = 09b3acc1-9c76-4060-a18f-5b5f253925cc
57+
EndGlobalSection
5258
EndGlobal

0 commit comments

Comments
 (0)