Skip to content

Commit bbdebf4

Browse files
committed
Add plugin for url (string)
1 parent 33fab74 commit bbdebf4

File tree

5 files changed

+132
-1
lines changed

5 files changed

+132
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ UpgradeLog*.htm
174174
# Microsoft Fakes
175175
FakesAssemblies/
176176
ObjectFillerNET.v2.ncrunchsolution
177+
ObjectFillerNET.v3.ncrunchsolution
177178
ObjectFiller/ObjectFiller.v2.ncrunchproject
178179
ObjectFiller.Test/ObjectFiller.Test.v2.ncrunchproject
179180
.vs/config/applicationhost.config

Tynamix.ObjectFiller.Test/Tynamix.ObjectFiller.Test.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
<Compile Include="TestPoco\TestEnum.cs" />
103103
<Compile Include="Properties\AssemblyInfo.cs" />
104104
<Compile Include="UriTest.cs" />
105+
<Compile Include="UrlTests.cs" />
105106
</ItemGroup>
106107
<ItemGroup>
107108
<None Include="packages.config" />

Tynamix.ObjectFiller.Test/UriTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ internal class UriTestClass
5656
}
5757

5858
[TestMethod]
59-
public void TestIpAddressGenerator()
59+
public void TestUriGenerator()
6060
{
6161
Filler<UriTestClass> filler = new Filler<UriTestClass>();
6262

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
using System;
2+
using Microsoft.VisualStudio.TestTools.UnitTesting;
3+
using Tynamix.ObjectFiller;
4+
5+
namespace ObjectFiller.Test
6+
{
7+
[TestClass]
8+
public class UrlTest
9+
{
10+
[TestMethod]
11+
public void RandomUrlIsReturned()
12+
{
13+
var sut = new RandomUrl();
14+
var value = sut.GetValue();
15+
Assert.IsNotNull(value);
16+
17+
var uri = new Uri(value);
18+
19+
Assert.IsFalse(string.IsNullOrEmpty(uri.Host));
20+
Assert.IsFalse(string.IsNullOrEmpty(uri.Scheme));
21+
Assert.IsFalse(string.IsNullOrEmpty(uri.PathAndQuery));
22+
}
23+
24+
[TestMethod]
25+
public void Returns_Http_When_Set()
26+
{
27+
var sut = new RandomUrl(RandomUri.SchemeType.Http);
28+
var value = sut.GetValue();
29+
Assert.IsNotNull(value);
30+
31+
var uri = new Uri(value);
32+
Assert.AreEqual("http", uri.Scheme);
33+
}
34+
35+
[TestMethod]
36+
public void Returns_Https_When_Set()
37+
{
38+
var sut = new RandomUrl(RandomUri.SchemeType.Https);
39+
var value = sut.GetValue();
40+
Assert.IsNotNull(value);
41+
42+
var uri = new Uri(value);
43+
Assert.AreEqual("https", uri.Scheme);
44+
}
45+
46+
[TestMethod]
47+
public void Returns_Configured_Domain_When_Set()
48+
{
49+
var sut = new RandomUrl(RandomUri.SchemeType.Https, new[] { "net" });
50+
var value = sut.GetValue();
51+
Assert.IsNotNull(value);
52+
53+
var uri = new Uri(value);
54+
Assert.AreEqual("https", uri.Scheme);
55+
Assert.IsTrue(uri.Host.EndsWith(".net"));
56+
}
57+
58+
internal class UriTestClass
59+
{
60+
public string RemoteUrl { get; set; }
61+
}
62+
63+
[TestMethod]
64+
public void TestUrlGenerator()
65+
{
66+
Filler<UriTestClass> filler = new Filler<UriTestClass>();
67+
68+
filler.Setup()
69+
.OnProperty(x => x.RemoteUrl).Use<RandomUrl>();
70+
71+
var result = filler.Create();
72+
73+
var url = result.RemoteUrl;
74+
75+
Assert.IsFalse(string.IsNullOrEmpty(url));
76+
}
77+
}
78+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Text;
4+
using static Tynamix.ObjectFiller.RandomUri;
5+
6+
namespace Tynamix.ObjectFiller
7+
{
8+
/// <summary>
9+
/// Creates a random Url
10+
/// </summary>
11+
public class RandomUrl : IRandomizerPlugin<string>
12+
{
13+
private readonly RandomUri _uri;
14+
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="RandomUrl"/> class.
17+
/// </summary>
18+
public RandomUrl()
19+
{
20+
_uri = new RandomUri();
21+
}
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="RandomUrl"/> class.
25+
/// </summary>
26+
/// <param name="schemeType">Type of the scheme.</param>
27+
public RandomUrl(SchemeType schemeType)
28+
{
29+
_uri = new RandomUri(schemeType);
30+
}
31+
32+
/// <summary>
33+
/// Initializes a new instance of the <see cref="RandomUrl" /> class.
34+
/// </summary>
35+
/// <param name="schemeType">Type of the scheme.</param>
36+
/// <param name="domainNames">The possible domain names.</param>
37+
public RandomUrl(SchemeType schemeType, IEnumerable<string> domainNames)
38+
{
39+
_uri = new RandomUri(schemeType, domainNames);
40+
}
41+
42+
/// <summary>
43+
/// Gets random data for type <see cref="string" />
44+
/// </summary>
45+
/// <returns>Random data for type <see cref="string" /></returns>
46+
public string GetValue()
47+
{
48+
return _uri.GetValue().ToString();
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)