public void RssTestJson() { SimplTypesScope simplTypesScope = SimplTypesScope.Get("rss", typeof(Rss), typeof(Channel), typeof(Item)); List <String> categorySet = new List <String> { "cate\\dgory1", "category2" }; Item item1 = new Item("testItem1", "testItem1Description", new ParsedUri("http://www.google.com"), "asdf", "nabeel", categorySet); Item item2 = new Item("testItem2", "testItem2Description", new ParsedUri("http://www.google.com"), "asdf", "nabeel", categorySet); Channel c = new Channel("testTile", "testDesc", new ParsedUri("http://www.google.com"), new List <Item> { item1, item2 }); Rss rss = new Rss(1.4f, c); TestMethods.TestSimplObject(rss, simplTypesScope, Format.Json); }
public void Run() { foreach (var t in _indexes) { TestMethods.Float2TestingMethod(t); } }
public void TestRequestVoteConsistencyCheck() { var node = TestMethods.CreateNode(); // Append dummy entry with term 1 var entry1 = new LogEntry(1, 0, "2"); var entry2 = new LogEntry(2, 1, "3"); node.AppendEntries(1, 1, 0, 0, new List <LogEntry>() { entry1, entry2 }, 0); // node.Log.Count - 1 --> 1 Assert.Equal(1, node.Log.Count - 1); // node.LastLogTerm --> 2 Assert.Equal(2, node.Log[node.Log.Count - 1].TermNumber); // pass consistency check var res = node.RequestVote(2, 2, 1, 2); Assert.True(res.Value); // outdated lastlogindex // if lastLogIndex >= Log.Count - 1 is false, no vote res = node.RequestVote(2, 2, 0, 2); Assert.False(res.Value); // outdated lastlogterm // if lastLogTerm >= GetLastLogTerm() is false, no vote res = node.RequestVote(2, 2, 1, 1); Assert.False(res.Value); }
public void Run() { for (var i = 0; i < _indexes.Length; i++) { TestMethods.Float2TestingMethod(_indexes[i]); } }
public void TimeoutExceededWithMissingConfiguration() { var exception = Assert.Throws <ArgumentException>(() => TestMethods.AddTimeoutWithMissingConfiguration()); Assert.Equal($"Could not find timeout configuration setting for " + $"key {MissingConfigurationItemKey}", exception.Message); }
static async Task <int> Main() { var builder = new HostBuilder().ConfigureAppConfiguration((host, config) => { config.SetBasePath(Environment.CurrentDirectory); config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: false); config.AddEnvironmentVariables(); }).ConfigureServices((host, services) => { services.AddHttpClient(); services.Configure <CloudProviderClientSettings>(host.Configuration.GetSection(nameof(CloudProviderClientSettings))); services.Configure <WorkspaceSettings>(host.Configuration.GetSection(nameof(WorkspaceSettings))); services.AddTransient <IAwsRangeClient, AwsRangeClient>(); services.AddTransient <IAzureRangeClient, AzureRangeClient>(); }).UseConsoleLifetime(); var host = builder.Build(); using var serviceScope = host.Services.CreateScope(); var services = serviceScope.ServiceProvider; try { var test = new TestMethods(services); var map = await test.RetrieveIPv4PrefixMap(); test.SearchIPv4PrefixMap(map); } catch (Exception e) { var logger = services.GetRequiredService <ILogger <Program> >(); logger.LogError(e, "An unknown error occured."); } return(0); }
public void TestGetAgent() { TestMethods testGetAgent = new TestMethods(); var sut = testGetAgent.GetAgent(); Assert.AreEqual("Edward", sut.tempArray[1].FirstName); }
public void TestBearerToken() { TestMethods testBearerToken = new TestMethods(); var sut = testBearerToken.GetBearerToken(); Assert.AreEqual(175, sut.Length); }
public void TestStatusCodeOfBearerToken() { TestMethods testReturningStatusCode = new TestMethods(); var sut = testReturningStatusCode.ReturningStatusCode(); Assert.AreEqual(HttpStatusCode.OK, sut); }
public void FileIsCopiedCorrectlyForNumberOfBitsBetween8And32() { var stopWatch = new Stopwatch(); using (var fileReader = new FileReader(filePathSource, new Buffer())) { using (var fileWriter = new FileWriter(filePathDestination, new Buffer())) { stopWatch.Start(); while (!fileReader.ReachedEndOfFile) { var random = new Random(); var numberOfBits = fileReader.BitsLeft < 32 ? (byte)fileReader.BitsLeft : (byte)random.Next(8, 32); var readStuff = fileReader.ReadBits(numberOfBits); fileWriter.WriteValueOnBits(readStuff, numberOfBits); } stopWatch.Stop(); } } Console.WriteLine($"File copying in '{TestMethods.GetCurrentMethodName()}' took {stopWatch.ElapsedMilliseconds} ms for {originalFileSizeInBytes} bytes"); Assert.IsTrue(TestMethods.FilesHaveTheSameContent(filePathSource, filePathDestination)); }
public void TimeoutExceededWithMisconfiguredConfiguration() { var exception = Assert.Throws <ArgumentException>(() => TestMethods.AddTimeoutWithMisconfiguredConfiguration()); Assert.Equal($"Timeout configuration setting for key {MisconfiguredConfigurationItemKey} " + $"must be an integer", exception.Message); }
public void TestGetCommittedEntries() { var node = TestMethods.CreateNode(); // Empty when log is empty Assert.Empty(node.GetCommittedEntries()); var entry1 = new LogEntry(1, 1, "2"); var entry2 = new LogEntry(1, 2, "4"); node.AppendEntries(1, 2, 0, 0, new List <LogEntry>() { entry1, entry2 }, 0); var committed = node.GetCommittedEntries(); Assert.NotEmpty(committed); Assert.Single(committed); Assert.Equal(2, node.Log.Count); Assert.Equal(entry1, committed[0]); node.AppendEntries(5, 2, 0, 0, null, 1); committed = node.GetCommittedEntries(); Assert.NotEmpty(committed); Assert.Equal(2, committed.Count); Assert.Equal(entry2, committed[1]); }
private TestClass(string path, string name, int line, TestMethods testMethods) { Path = path; Name = name; Line = line; TestMethods = testMethods; }
public void TestLogReplicationDictionary() { // Only test log replication works int nodeCount = 3; RaftNode[] nodes = TestMethods.ConfigureAndRunRaftCluster(nodeCount, SM.Dictionary); Thread.Sleep(TestMethods.WAIT_MS); nodes[0].MakeRequest("SET X 10"); nodes[1].MakeRequest("SET Y 22"); Thread.Sleep(TestMethods.WAIT_MS); foreach (var node in nodes) { Assert.Equal("SET X 10", node.Log[0].Command); Assert.Equal(0, node.Log[0].Index); Assert.Equal("SET Y 22", node.Log[1].Command); Assert.Equal(1, node.Log[1].Index); Assert.Equal(2, node.GetCommittedEntries().Count); } Array.ForEach(nodes, x => x.Stop()); }
public void TestStopRestartNode() { int nodeCount = 3; RaftNode[] nodes = TestMethods.ConfigureAndRunRaftCluster(nodeCount, SM.Dictionary); Thread.Sleep(TestMethods.WAIT_MS); nodes[2].Stop(); Thread.Sleep(TestMethods.WAIT_MS); nodes[0].MakeRequest("SET X 10"); nodes[1].MakeRequest("SET Y 22"); Thread.Sleep(TestMethods.WAIT_MS); nodes[2].Restart(); Thread.Sleep(TestMethods.WAIT_MS); foreach (var node in nodes) { // Console.WriteLine(node.ToString()); Assert.Equal("SET X 10", node.Log[0].Command); Assert.Equal(0, node.Log[0].Index); Assert.Equal("SET Y 22", node.Log[1].Command); Assert.Equal(1, node.Log[1].Index); Assert.Equal(2, node.GetCommittedEntries().Count); } Array.ForEach(nodes, x => x.Stop()); }
public void TimeoutNotExceededNonAsync() { TestMethods.AddTimeout(providedToken => { // A CancellationToken should have been provided by the Aspect Assert.NotNull(providedToken); }); }
public void Run() { for (var index = 0; index < _indexes.Length; index++) { var t = _indexes[index]; TestMethods.Float2TestingMethod(t); } }
// [TestMethod] public void CircleTlv() { Circle c = new Circle(new Point(1, 3), 3); SimplTypesScope circleTransaltionScope = SimplTypesScope.Get("circleTScope", typeof(Circle), typeof(Point)); TestMethods.TestSimplObject(c, circleTransaltionScope, Format.Tlv); }
public void MapsWithinMapsTestJson() { TranslationS test = MapsWithinMaps.CreateObject(); SimplTypesScope tScope = SimplTypesScope.Get("testScope", typeof(TranslationS), typeof(ClassDes), typeof(FieldDes)); TestMethods.TestSimplObject(test, tScope, Format.Json); }
public void Setup() { filePath = $"{Environment.CurrentDirectory}\\{Constants.TestFileName}"; buffer = new Buffer(); TestMethods.CreateFileWithGivenBytes(filePath, Constants.TestBytes); fileReader = new FileReader(filePath, buffer); }
public async Task TimeoutNotExceededAsync() { await TestMethods.AddTimeoutAsync(providedToken => { // A CancellationToken should have been provided by the Aspect Assert.NotNull(providedToken); return(Task.CompletedTask); }); }
public void TestThatFileIsEncodedThenDecodedCorrectly(string fileTextContents) { TestMethods.CreateFileWithTextContents(filepathSource, fileTextContents); arithmeticEncoder.EncodeFile(filepathSource, filepathEncodedFile); arithmeticDecoder.DecodeFile(filepathEncodedFile, filepathDecodedFile); Assert.IsTrue(TestMethods.FilesHaveTheSameContent(filepathSource, filepathDecodedFile)); }
public void TestApplyEntryFail() { var node = TestMethods.CreateNode(); var entry = new LogEntry(1, 1, "2"); var res = node.AppendEntries(1, 2, 0, 0, null, 14); // The node doesn't have entries in its log matching the commit index Assert.False(res.Value); }
public void CompositeSubTwoJson() { Container c = new Container(new WcSubTwo(true, 1)); SimplTypesScope simplTypesScope = SimplTypesScope.Get("compositeTScope", typeof(Container), typeof(WcBase), typeof(WcSubOne), typeof(WcSubTwo)); TestMethods.TestSimplObject(c, simplTypesScope, Format.Json); }
public void CompositeSubOneXml() { Container c = new Container(new WcSubOne("testing", 1)); SimplTypesScope simplTypesScope = SimplTypesScope.Get("compositeTScope", typeof(Container), typeof(WcBase), typeof(WcSubOne), typeof(WcSubTwo)); TestMethods.TestSimplObject(c, simplTypesScope); }
public void Setup() { filePathSource = $"{Environment.CurrentDirectory}\\{Constants.TestFileNameImage}"; filePathDestination = $"{Environment.CurrentDirectory}\\{Constants.TestFileNameImageDestination}"; TestMethods.CreateBmpFileFromImage(filePathSource, Resources.testImage); originalFileSizeInBytes = new FileInfo(filePathSource).Length; }
public void TestLeaderElection() { int nodeCount = 3; RaftNode[] nodes = TestMethods.ConfigureAndRunRaftCluster(nodeCount, SM.Dictionary); Thread.Sleep(TestMethods.WAIT_MS); int candidates = 0; int leaders = 0; int followers = 0; foreach (var node in nodes) { if (node.NodeState == NodeState.Candidate) { candidates++; } else if (node.NodeState == NodeState.Leader) { leaders++; } else if (node.NodeState == NodeState.Follower) { followers++; } } // Array.ForEach(nodes, x => Console.WriteLine(x.ToString())); Array.ForEach(nodes, x => x.Stop()); if (followers == nodeCount) { // Valid state 2 Assert.Equal(0, candidates); Assert.Equal(nodeCount, followers); Assert.Equal(0, candidates); foreach (var node in nodes) { Assert.Null(node.LeaderId); } // all the LeaderId are null? } else if (candidates > 0) { // Valid state 2 ; // TODO } else { // Valid state 3 Assert.Equal(0, candidates); Assert.Equal(nodeCount - 1, followers); Assert.Equal(1, leaders); } }
public void EquivilantListsAndMapsAreTreatedCorreclty() { var classA = createInstance(); var classB = createInstance(); Assert.IsTrue(ClassDescriptor.GetClassDescriptor(classA.GetType()).AllFieldDescriptors.Count() == 2, "Incorrect number of field descriptors"); Assert.IsFalse(classA == classB, "Should be different instances"); Assert.IsFalse(TestMethods.CompareOriginalObjectToDeserializedObject(classA, classB).Any(), "Class A and B should be the same... their collections are equivilant."); }
public void TestMakeRequestToLeader() { var node = TestMethods.CreateNode(); node.Run(); Thread.Sleep(TestMethods.WAIT_MS); Assert.Equal(NodeState.Leader, node.NodeState); node.MakeRequest("2"); Assert.Equal("2", node.Log[0].Command); }
public ITestFormatter AddTestMethod(string methodName, string testBody) { TestMethods.Add(string.Format(@" @Test public void Check_{0}(){{ {1} }}", methodName, testBody)); return(this); }