Skip to content

Commit

Permalink
updated uses of random number generation in tests so that we log the …
Browse files Browse the repository at this point in the history
…seed used for later investigation
  • Loading branch information
corranrogue9 committed Mar 7, 2022
1 parent 0a23c07 commit 1193aab
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.OData.Client;
Expand Down Expand Up @@ -69,7 +70,10 @@ public async Task SupportPostCollectionPropertyByEntityPayload()
// clear respository
await this.ClearRepositoryAsync("CollectionProperty_Entity");

var rand = new Random(RandomSeedGenerator.GetRandomSeed());
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var rand = new Random(seed);

// post new entity to repository
var baseline = InstanceCreator.CreateInstanceOf<CollectionProperty_Entity>(rand, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.OData.Client;
Expand Down Expand Up @@ -66,7 +67,10 @@ public async Task ShouldSupportDerivedComplexTypeAsync()
// clear respository
await this.ClearRepositoryAsync("ComplexTypeTests_Entity");

var rand = new Random(RandomSeedGenerator.GetRandomSeed());
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var rand = new Random(seed);

// post new entity to repository
var baseline = InstanceCreator.CreateInstanceOf<ComplexTypeTests_Entity>(rand, settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#else
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.ComponentModel;
using System.Dynamic;
using System.Linq;
Expand Down Expand Up @@ -222,7 +223,10 @@ public async Task TestApplyPatchOnIndividualProperty()

await this.Client.GetStringAsync(this.BaseAddress + "/$metadata");

Random r = new Random(RandomSeedGenerator.GetRandomSeed());
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var r = new Random(seed);

var s = new CreatorSettings()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
Expand Down Expand Up @@ -271,7 +272,10 @@ public async Task PostGetUpdateAndDelete(Type entityType, string entitySetNam)
.FirstOrDefault();

var concreteTestMethod = testMethod.MakeGenericMethod(entityType);
var rand = new Random(RandomSeedGenerator.GetRandomSeed());
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var rand = new Random(seed);

await (Task)concreteTestMethod.Invoke(this, new object[] { entitySetNam, rand });
}
Expand Down Expand Up @@ -387,7 +391,10 @@ public virtual async Task AddAndRemoveBaseNavigationPropertyInDerivedType()
// clear respository
await this.ClearRepositoryAsync("InheritanceTests_Cars");

Random r = new Random(RandomSeedGenerator.GetRandomSeed());
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var r = new Random(seed);

// post new entity to repository
CreatorSettings creatorSettings = new CreatorSettings()
Expand Down Expand Up @@ -429,7 +436,10 @@ public virtual async Task AddAndRemoveDerivedNavigationPropertyInDerivedType()
// clear respository
await this.ClearRepositoryAsync("InheritanceTests_Cars");

Random r = new Random(RandomSeedGenerator.GetRandomSeed());
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var r = new Random(seed);

// post new entity to repository
CreatorSettings creatorSettings = new CreatorSettings()
Expand Down Expand Up @@ -471,7 +481,10 @@ public virtual async Task CreateAndDeleteLinkToDerivedNavigationPropertyOnBaseEn
// clear respository
await this.ClearRepositoryAsync("InheritanceTests_Vehicles");

Random r = new Random(RandomSeedGenerator.GetRandomSeed());
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var r = new Random(seed);

// post new entity to repository
CreatorSettings creatorSettings = new CreatorSettings()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//------------------------------------------------------------------------------

using System;
using System.Diagnostics;
using System.Net.Http;
using System.Net.Http.Headers;
using Microsoft.Test.E2E.AspNet.OData.Common.Instancing;
Expand All @@ -22,7 +23,12 @@ public static void SetAcceptHeader(this HttpRequestMessage message, string accep

public static T CreateInstances<T>()
{
var results = InstanceCreator.CreateInstanceOf<T>(new Random(RandomSeedGenerator.GetRandomSeed()), new CreatorSettings { NullValueProbability = 0, AllowEmptyCollection = false });
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var random = new Random(seed);

var results = InstanceCreator.CreateInstanceOf<T>(random, new CreatorSettings { NullValueProbability = 0, AllowEmptyCollection = false });

return results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
Expand Down Expand Up @@ -36,7 +37,11 @@ public static ODataModelTypeCreator Creator
if (creator == null)
{
creator = new ODataModelTypeCreator();
creator.CreateTypes(50, new Random(RandomSeedGenerator.GetRandomSeed()));
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var random = new Random(seed);
creator.CreateTypes(50, random);
}
return creator;
}
Expand Down Expand Up @@ -77,7 +82,10 @@ public async Task TestRandomEntityTypesAsync<T>(string entitySetName)
await this.ClearRepositoryAsync(entitySetName);

// TODO: Get ride of random generator in test codes. It's bad idea to introduce random factors in functional test
var rand = new Random(RandomSeedGenerator.GetRandomSeed());
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var rand = new Random(seed);

T entityBaseline = await PostNewEntityAsync<T>(entitySetName, rand);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.OData.Client;
Expand Down Expand Up @@ -72,7 +73,10 @@ protected static IEdmModel GetEdmModel(WebRouteConfiguration configuration)
[Fact]
public async Task CRUDEntitySetShouldWork()
{
var rand = new Random(RandomSeedGenerator.GetRandomSeed());
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var rand = new Random(seed);
var entitySetName = "UnicodeRouteTests_Todoü";
var uri = new Uri(this.BaseAddress + "/odataü");
var context = new DataServiceContext(uri, ODataProtocolVersion.V4);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public static TheoryDataSet<string> FuzzingQueries
{
var data = new TheoryDataSet<string>();
int seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var ranGen = new Random(seed);

for (int i = 5; i <= 10; i += 5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,11 @@ public static ODataModelTypeCreator Creator
if (creator == null)
{
creator = new ODataModelTypeCreator();
creator.CreateTypes(100, new Random(RandomSeedGenerator.GetRandomSeed()));
var seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

var random = new Random(seed);
creator.CreateTypes(100, random);
}
return creator;
}
Expand Down Expand Up @@ -221,6 +225,8 @@ private static string BuildFilterString(Type type)
public void RunQueryableOnAllPossibleTypes(Type type, string queryString)
{
int seed = RandomSeedGenerator.GetRandomSeed();
Trace.WriteLine($"Generated seed for random number generator: {seed}");

Random r = new Random(seed);
Type generic = typeof(IEnumerable<>);
var collectionType = generic.MakeGenericType(type);
Expand Down

0 comments on commit 1193aab

Please sign in to comment.