Exemplo n.º 1
0
            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();
            }
Exemplo n.º 2
0
            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());
            }
Exemplo n.º 3
0
            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);
            }
Exemplo n.º 4
0
            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
            }