private static void CheckContacts(XmlNode ctrNode, List<Contact> contacts) { var jnode = ctrNode.GetXmlAttribute("J"); var knode = ctrNode.GetXmlAttribute("K"); var lnode = ctrNode.GetXmlAttribute("L"); var mnode = ctrNode.GetXmlAttribute("M"); if (!string.IsNullOrEmpty(jnode)) { var fixedPhoneContact = contacts.Single(x => x.Type == ContactTypeEnum.FixedPhone); Assert.AreEqual(jnode, fixedPhoneContact.Number); } if (!string.IsNullOrEmpty(knode)) { var mobilePhoneContact = contacts.Single(x => x.Type == ContactTypeEnum.MobilePhone); Assert.AreEqual(knode, mobilePhoneContact.Number); } if (!string.IsNullOrEmpty(lnode)) { var faxContact = contacts.Single(x => x.Type == ContactTypeEnum.Fax); Assert.AreEqual(lnode, faxContact.Number); } if (!string.IsNullOrEmpty(mnode)) { var emailContact = contacts.Single(x => x.Type == ContactTypeEnum.Email); Assert.AreEqual(mnode, emailContact.Number); } }
public void TestFooList() { var orig = new List<Foo> { new Foo() { Count = 12, Name = "abc" } }; var clone = Serializer.DeepClone(orig).Single(); Assert.AreEqual(orig.Single().Count, clone.Count); Assert.AreEqual(orig.Single().Name, clone.Name); }
public void StillRaisesSendingEventWhenSendingThrows() { var sendingEvents = new List<RequestDetails>(); var client = new RestClient(new Uri(BaseAddress), new AlwaysThrowsOnSendingAdapter(), new List<PipelineOption>()); client.Sending += (sender, args) => sendingEvents.Add(args.Request); Assert.That(() => client.Get("/foo?omg=yeah"), Throws.InstanceOf<DeliberateException>()); Assert.That(sendingEvents.Single().RequestUri.PathAndQuery, Is.EqualTo("/foo?omg=yeah")); Assert.That(sendingEvents.Single().Method, Is.EqualTo("GET")); }
public void RaisesRespondedEventForEachRequest() { _server.OnGet("/foo").Respond((req, res) => res.StatusCode = 418); var client = new RestClient(BaseAddress); var respondedEvents = new List<ResponseEventArgs>(); client.Responded += (sender, args) => respondedEvents.Add(args); client.Get("/foo?teapot=yes", new ExpectStatus((HttpStatusCode)418)); Assert.That(respondedEvents.Single().Response.Status, Is.EqualTo(418)); Assert.That(respondedEvents.Single().Request.RequestUri.PathAndQuery, Is.EqualTo("/foo?teapot=yes")); }
public void RaisesSendingEventForEachRequest() { _server.OnGet("/foo").RespondWith("awww yeah"); var client = new RestClient(BaseAddress); var sendingEvents = new List<RequestDetails>(); client.Sending += (sender, args) => sendingEvents.Add(args.Request); client.Get(BaseAddress + "/foo?omg=yeah"); Assert.That(sendingEvents.Single().RequestUri.PathAndQuery, Is.EqualTo("/foo?omg=yeah")); Assert.That(sendingEvents.Single().Method, Is.EqualTo("GET")); client.Get(BaseAddress + "/foo?omg=nah"); Assert.That(sendingEvents.Skip(1).Single().RequestUri.PathAndQuery, Is.EqualTo("/foo?omg=nah")); Assert.That(sendingEvents.Skip(1).Single().Method, Is.EqualTo("GET")); }
public async Task from_instance_method_in_derived_class_show_correct_CallingType() { var entries = new List<LogEntry>(); using (Log.Events().Subscribe(entries.Add)) { var widget = new InheritedWidget(); await widget.DoStuffAsync(); } Assert.That(entries.Single(e => e.EventType == TraceEventType.Start).CallingType, Is.EqualTo(typeof (InheritedWidget))); Assert.That(entries.Single(e => e.EventType == TraceEventType.Stop).CallingType, Is.EqualTo(typeof (InheritedWidget))); }
public void from_instance_method_in_nested_class_show_correct_CallingMethod() { var log = new List<LogEntry>(); using (Log.Events().Subscribe(log.Add)) { var widget = new BoundaryTests.NestedWidget(); widget.DoStuff(); } Assert.That(log.Single(e => e.EventType == TraceEventType.Start).CallingMethod, Is.EqualTo("DoStuff")); Assert.That(log.Single(e => e.EventType == TraceEventType.Start).CallingMethod, Is.EqualTo("DoStuff")); }
public void from_instance_method_in_derived_class_show_correct_CallingMethod() { var entries = new List<LogEntry>(); using (Log.Events().Subscribe(entries.Add)) { var widget = new InheritedWidget(); widget.DoStuff(); } Assert.That(entries.Single(e => e.EventType == TraceEventType.Start).CallingMethod, Is.EqualTo("DoStuff")); Assert.That(entries.Single(e => e.EventType == TraceEventType.Stop).CallingMethod, Is.EqualTo("DoStuff")); }
public void AddUsersToRoles() { var users = new List<User> { new User {Username = "******", Email = "*****@*****.**", Password = "******"}, new User {Username = "******", Email = "*****@*****.**",Password = "******"}, }; _Tests.MockStorage.Setup(s => s.GetCurrentUser()).Returns(_Tests.Storage.GetUser(u => u.Username == "panza")); foreach (var user in users) { _Tests.Storage.CreateUser(user); } var usernames = users.Select(u => u.Username); var roles = new List<Role> {Role.Teacher}; _Tests.Storage.AddUsersToRoles(usernames, roles); foreach (var user in users) { Assert.IsTrue(_Tests.Storage.GetUserRoles(user.Username).Contains(roles.Single())); } _Tests.Storage.RemoveUsersFromRoles(usernames, roles); }
public void Should_handle_TypeLoadException_and_find_1_event_listener() { // Arrange var log = new List<string>(); SecurityDoctor.Register(e => log.Add(e.Message)); var throwException = true; const string expectedExceptionMessage = "Could not load type X."; Func<Assembly, Type[]> assemblyTypeProvider = assembly => { if (throwException) { throwException = false; throw new TypeLoadException(expectedExceptionMessage); } return assembly.GetExportedTypes(); }; var scanner = new SecurityEventListenerScanner(true, assemblyTypeProvider); var assemblies = new List<Assembly> { GetType().Assembly, GetType().Assembly }; // Act var types = scanner.Scan(assemblies); // Assert Assert.That(types.Count(), Is.EqualTo(1)); Assert.That(log.Single(), Is.EqualTo(expectedExceptionMessage)); }
public void Should_produce_configuration_event_with_timing_when_event_listener_is_registered() { // Arrange const int expectedMilliseconds = 9; var expectedResult = new { }; const string expectedMessage = "Message"; var events = new List<ISecurityEvent>(); SecurityDoctor.Register(events.Add); // Act var result = Publish.ConfigurationEvent(() => { Thread.Sleep(expectedMilliseconds + 5); return expectedResult; }, r => expectedMessage); // Assert Assert.That(result, Is.EqualTo(expectedResult)); var @event = events.Single(); Assert.That(@event.CorrelationId, Is.EqualTo(SecurityConfigurator.CorrelationId)); Assert.That(@event.Message, Is.EqualTo(expectedMessage)); Assert.That(@event.CompletedInMilliseconds, Is.GreaterThanOrEqualTo(expectedMilliseconds)); }
public void AddExistingUsersToRoles() { tests = UserManagementTests.Update(); var users = new List<User> { new User { Username = "******", Email = "*****@*****.**", Password = "******" }, new User { Username = "******", Email = "*****@*****.**", Password = "******" }, }; foreach (var user in users) { this.tests.Storage.CreateUser(user); } var usernames = users.Select(u => u.Username); var roles = new List<Role> { Role.Teacher }; this.tests.Storage.AddUsersToRoles(usernames, roles); foreach (var user in users) { Assert.IsTrue(this.tests.Storage.GetUserRoles(user.Username).Contains(roles.Single())); } this.tests.Storage.RemoveUsersFromRoles(usernames, roles); foreach (var user in users) { this.tests.Storage.DeleteUser(u => u.Username == user.Username); } }
public void AddExistingUsersToRoles() { var users = new List<User> { new User {Username = "******", Email = "*****@*****.**", Password = "******"}, new User {Username = "******", Email = "*****@*****.**",Password = "******"}, }; _Tests.MockStorage.Setup(s => s.GetCurrentUser()).Returns(_Tests.Storage.GetUser(u => u.Username == "panza")); foreach (var user in users) { _Tests.Storage.CreateUser(user); } var usernames = users.Select(u => u.Username); var roles = new List<Role> {Role.Teacher}; _Tests.Storage.AddUsersToRoles(usernames, roles); foreach (var user in users) { Assert.IsTrue(_Tests.Storage.GetUserRoles(user.Username).Contains(roles.Single())); } _Tests.Storage.RemoveUsersFromRoles(usernames, roles); foreach (var user in users) { _Tests.Storage.DeleteUser(u => u.Username == user.Username); } }
public void Get_Payroll_For_2012_7_1() { var adapter = new PayrollAdapter(); Payroll[] payrollItems = adapter.GetPayrollWeekEnding(DateTime.Parse("2012-7-1")); List<Payroll> list = new List<Payroll>(payrollItems); Payroll payroll = list.Single(x => x.Lastname == "Denton"); Assert.AreEqual(32, payroll.RegularHours); }
public void messages_with_string() { var stringCheck = AccessorPersistenceCheck.For<CheckTarget>(x => x.Name); original.Name = "Jeremy"; persisted.Name = "Max"; var list = new List<string>(); stringCheck.CheckValue(original, persisted, list.Add); list.Single().ShouldEqual("Name: original was 'Jeremy', but the persisted value was 'Max'"); }
public void ExactMatchIsEqualToMaxHopsCounter() { var relatedInterests = new List<WeightedRelatedInterestDto> { new WeightedRelatedInterestDto(0, new List<float>(), "", false) }; _interestScoreCalculator.CalculateRelatedInterestScore(relatedInterests); Assert.That(relatedInterests.Single().Score, Is.EqualTo(_maxHopsInverter)); }
public void ScoreIsCalculatedCorrectly(float[] weights, float expectedScore) { var constructedRelatedInterest = new WeightedRelatedInterestDto(0, weights.ToList(), "", false); var relatedInterests = new List<WeightedRelatedInterestDto> { constructedRelatedInterest }; _interestScoreCalculator.CalculateRelatedInterestScore(relatedInterests); Assert.That(relatedInterests.Single().Score, Is.EqualTo(expectedScore)); }
public void CurrentFilterItem_WhenSetToNull_AddsAllTransactions() { var transactions = new List<Transaction> { new Transaction() }; TransactionListViewModel viewModel = CreateTransactionListViewModel(transactions); viewModel.CurrentFilterItem = null; Assert.AreEqual(transactions.Single(), viewModel.Transactions.Single().Model); }
public void TestCreateCustom() { string customType = typeof(CustomEndpointStrategy).AssemblyQualifiedName; IEnumerable<IPAddress> endpoints = new List<IPAddress> {null}; IEndpointStrategy endpointStrategy = CassandraSharp.EndpointStrategy.Factory.Create(customType, endpoints, new SimpleSnitch()); CustomEndpointStrategy customEndpointStrategy = endpointStrategy as CustomEndpointStrategy; Assert.IsNotNull(customEndpointStrategy); IPAddress customEndpoint = customEndpointStrategy.Endpoints.Single(); Assert.AreEqual(customEndpoint, endpoints.Single()); }
public void When_there_is_only_one_exact_match_it_only_looks_for_exact_and_finds_it() { var finderOptions = FinderOptions(); var finder = new StubElementFinder(finderOptions); var exactResults = new List<ElementFound> { new StubElement() }; StubExactResults(finder, finderOptions, exactResults); var results = ResolveQuery(finder); Assert.That(results, Is.SameAs(exactResults.Single())); }
public void SimpleAddTest() { var fakeInpc = new FakeInpc(); var oc = new ObservableCollection<FakeInpc>(); var events = new List<FakeInpc>(); var listener = OcNpcListener.Create(oc); listener.PropertyChanged += (sender, args) => events.Add((FakeInpc)((ChildPropertyChangedEventArgs)args).Child); Assert.IsFalse(fakeInpc.HasHandler); oc.Add(fakeInpc); Assert.IsTrue(fakeInpc.HasHandler); fakeInpc.Raise1(); Assert.AreEqual(fakeInpc, events.Single()); }
public void SimpleAddListenWithPropertyChangedEventManagerTest() { var fakeInpc = new FakeInpc(); var oc = new ObservableCollection<FakeInpc>(); var events = new List<ListenerAndChild<FakeInpc>>(); var listener = OcNpcListener.Create(oc); PropertyChangedEventManager.AddHandler(listener, (sender, args) => events.Add((ListenerAndChild<FakeInpc>)sender), ""); Assert.IsFalse(fakeInpc.HasHandler); oc.Add(fakeInpc); Assert.IsTrue(fakeInpc.HasHandler); fakeInpc.Raise1(); Assert.AreEqual(fakeInpc, events.Single().Child); }
private static ParentEntity Arrange() { // Arrange // Create untracked entities equivaelent to our collection // and then attempt to save and check list var childEntities = new List<ChildEntity> { new ChildEntity {Id = 1, Name = "ChildEntity 1", ParentEntityId = 1}, new ChildEntity {Id = default(long), Name = "ChildEntity 3", ParentEntityId = 1} }; var childEntityReferencingChildEntities = new List<ChildEntityReferencingChildEntity> { new ChildEntityReferencingChildEntity { Id = 1, Name = "ChildEntityReferencingChildEntity 1", ChildEntityId = 1, ChildEntity = childEntities.Single(x => x.Id == 1), ParentEntityId = 1 }, new ChildEntityReferencingChildEntity { Id = default(long), Name = "ChildEntityReferencingChildEntity 3", ChildEntityId = default(long), ChildEntity = childEntities.Last(), // untracked and not yet added ParentEntityId = 1 } }; // If this relationship is already established then the entities must be added childEntities.First().ChildEntityReferencingChildEntities = childEntityReferencingChildEntities.Where(x => x.ChildEntityId == 1).ToList(); // GraphDiff cannot handle this situation where a collection is added // Must have an existing Id or else EF fails. //childEntities.Last().ChildEntityReferencingChildEntities = // childEntityReferencingChildEntities.Where(x => x.ChildEntityId == default(long)).ToList(); var parentEntity = new ParentEntity { Id = 1, Name = "ParentEntity 1", ChildEntities = childEntities.Where(x => x.ParentEntityId == 1).ToList(), ChildReferencingChildEntities = childEntityReferencingChildEntities.Where(x => x.ParentEntityId == 1).ToList() }; return parentEntity; }
public void Constructor_WithOneAccount_AddsOneGroupWithOneItem() { var accounts = new List<Account> { new Account { AccountType = AccountType.CheckingAccount } }; TransactionFilterViewModel viewModel = CreateTransactionFilterViewModel(accounts); Assert.AreEqual( accounts.Single(), viewModel .FilterGroups.Single() .Items.Single() .Account); }
public static void AreEqual(Dictionary<string, List<UniqueId>> linkList, string isoRefId, List<UniqueId> adaptIds) { if(!linkList.ContainsKey(isoRefId)) return; var links = linkList[isoRefId]; foreach (var link in links) { var matchingAdaptId = adaptIds.Single(x => x.Id == link.Id); Assert.AreEqual(link.Source, matchingAdaptId.Source); Assert.AreEqual(link.SourceType, matchingAdaptId.SourceType); Assert.AreEqual(link.CiTypeEnum, matchingAdaptId.CiTypeEnum); } }
public void Given() { var customers = new List<Customer> { new Customer { Id = 1, FirstName = "FirstName1", LastName = "LastName1" }, new Customer { Id = 2, FirstName = "FirstName2", LastName = "LastName2" } }; var employeeRepository = A.Fake<ICustomerRepository>(); A.CallTo(() => employeeRepository.GetCustomerById(A<int>.Ignored)) .ReturnsLazily<Customer, int>(id => customers.Single(customer => customer.Id == id)); var sut = new CustomerService(employeeRepository); result = sut.GetCustomerNamesAsCsv(customers.Select(x => x.Id).ToArray()); }
public RequestControllerTest() { List<RegionalRequest> regionalRequestTest = new List<RegionalRequest>(); { new RegionalRequest { RegionalRequestID = 1, ProgramId = 1, Round = 2, RegionID = 9, ReferenceNumber = "AA1234", Year = 2012, Remark = "remarks" }; new RegionalRequest { RegionalRequestID = 2, ProgramId = 2, Round = 4, RegionID = 7, ReferenceNumber = "1234", Year = 2012, Remark = "" }; } ; List<AdminUnit> adminUnitTest=new List<AdminUnit>(); { new AdminUnit() {AdminUnitID = 1, Name = "Afar", NameAM = null, AdminUnitTypeID = 2, ParentID = 1}; } ; List<Commodity> commodityTest = new List<Commodity> { new Commodity { CommodityID = 5, Name = "Grain",LongName = "",CommodityTypeID = 1, ParentID = 1 }, new Commodity { CommodityID = 6, Name = "Oil",LongName = "",CommodityTypeID = 1, ParentID = 1 }, new Commodity { CommodityID = 8, Name = "CSB",LongName = "",CommodityTypeID = 1, ParentID = 3 }, }; //Mock the Regional Request Service Using Moq Mock<IRegionalRequestService> mockRegionalRequestService = new Mock<IRegionalRequestService>(); Mock<IFDPService> mockFDPService = new Mock<IFDPService>(); Mock<IAdminUnitService> mockAdminUnitService = new Mock<IAdminUnitService>(); Mock<IProgramService> mockProgramService = new Mock<IProgramService>(); Mock<ICommodityService> mockCommodityService = new Mock<ICommodityService>(); Mock<IRegionalRequestDetailService> mockRegionalRequestDetailService=new Mock<IRegionalRequestDetailService>(); // return all regional requests mockRegionalRequestService.Setup(m => m.GetAllReliefRequistion()).Returns(regionalRequestTest); mockRegionalRequestService.Setup(m => m.Get(t=>t.RegionalRequestID==2,null,null)); mockFDPService.Setup(m => m.GetAllFDP()).Returns(new List<FDP>()); mockAdminUnitService.Setup(m => m.FindBy(au => au.AdminUnitTypeID==2)).Returns(adminUnitTest); mockProgramService.Setup(m => m.GetAllProgram()).Returns(new List<Program>()); mockCommodityService.Setup(m => m.GetAllCommodity()).Returns(commodityTest); //return regional requests by id mockRegionalRequestService.Setup(mr => mr.FindById( It.IsAny<int>())).Returns((int i) => regionalRequestTest.Single(x => x.RegionalRequestID == i)); this.MockRegionalRequestService = mockRegionalRequestService.Object; this.MockAdminUnitService = mockAdminUnitService.Object; this.MockFdpService = mockFDPService.Object; this.MockProgramService = mockProgramService.Object; this.MockCommodityService = mockCommodityService.Object; this.MockRegionalRequestDetailService = mockRegionalRequestDetailService.Object; }
public void Should_produce_configuration_event_when_event_listener_is_registered() { // Arrange const string expectedMessage = "Message"; var events = new List<ISecurityEvent>(); SecurityDoctor.Register(events.Add); // Act Publish.ConfigurationEvent(() => expectedMessage); // Assert var @event = events.Single(); Assert.That(@event.CorrelationId, Is.EqualTo(SecurityConfigurator.CorrelationId)); Assert.That(@event.Message, Is.EqualTo(expectedMessage)); }
public void SpecifyingThatATypeIsScalarCausesItToBeLoggedAsScalarEvenWhenDestructuring() { var events = new List<LogEvent>(); var sink = new DelegatingSink(events.Add); var logger = new LoggerConfiguration() .WriteTo.Sink(sink) .Destructure.AsScalar(typeof(AB)) .CreateLogger(); logger.Information("{@AB}", new AB()); var ev = events.Single(); var prop = ev.Properties["AB"]; Assert.IsInstanceOf<ScalarValue>(prop.Value); }
public void recording_events_removes_the_events_from_the_node_and_calls_back() { var list = new List<NodeEvent>(); theTracedNode.RecordEvents(list.Add); list.Single().ShouldBeOfType<Created>(); theTracedNode.StagedEvents.Any().ShouldBeFalse(); theTracedNode.Trace("something"); theTracedNode.RecordEvents(list.Add); list.Last().ShouldBeOfType<Traced>().Text.ShouldEqual("something"); }