public void ReturnsNull_WhenQueryForUser_ReturnsNull() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var query = new GetMyAffiliationByEstablishmentIdQuery { Principal = principal, }; var affiliation = new Affiliation { Person = new Person { User = new User { Name = "something else" } }, }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <Affiliation>()).Returns(new[] { affiliation }.AsQueryable); var handler = new GetMyAffiliationByEstablishmentIdHandler(entities.Object); var result = handler.Handle(query); result.ShouldBeNull(); }
public void ExecutesQuery_ToGetUserByName() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var query = new GetMyAffiliationByEstablishmentIdQuery { Principal = principal, }; var affiliation = new Affiliation { Person = new Person { User = new User { Name = principal.Identity.Name } } }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <Affiliation>()).Returns(new[] { affiliation }.AsQueryable); var handler = new GetMyAffiliationByEstablishmentIdHandler(entities.Object); handler.Handle(query); entities.Verify(m => m.Query <Affiliation>(), Times.Once()); }
public void ReturnsEmailAddress_WhenMatchingUserAndNumber_IsFound() { const string principalIdentityName = "*****@*****.**"; var principal = principalIdentityName.AsPrincipal(); var query = new GetMyAffiliationByEstablishmentIdQuery { Principal = principal, EstablishmentId = 1, }; var affiliations = new[] { new Affiliation { EstablishmentId = 1, Person = new Person { User = new User { Name = principal.Identity.Name } } }, new Affiliation { EstablishmentId = 3, Person = new Person { User = new User { Name = principal.Identity.Name } } }, new Affiliation { EstablishmentId = 4, Person = new Person { User = new User { Name = principal.Identity.Name } } }, }; var entities = new Mock <IQueryEntities>(MockBehavior.Strict).Initialize(); entities.Setup(m => m.Query <Affiliation>()).Returns(affiliations.AsQueryable); var handler = new GetMyAffiliationByEstablishmentIdHandler(entities.Object); var result = handler.Handle(query); result.ShouldNotBeNull(); result.EstablishmentId.ShouldEqual(query.EstablishmentId); }
public void ThrowsArgumentNullException_WhenQueryArgIsNull() { var handler = new GetMyAffiliationByEstablishmentIdHandler(null); ArgumentNullException exception = null; try { handler.Handle(null); } catch (ArgumentNullException ex) { exception = ex; } exception.ShouldNotBeNull(); // ReSharper disable PossibleNullReferenceException exception.ParamName.ShouldEqual("query"); // ReSharper restore PossibleNullReferenceException }