protected override IAddressBookContactsService GetContactsService(
            InMemoryDataContext dataContext, ref IEnumerable <IAddressBookContact> contacts)
        {
            if (contacts != null)
            {
                dataContext.Contacts.AddRange(contacts);
            }
            contacts = dataContext.Contacts;

            dataContext.Users.Add(
                User = new InMemoryUser
            {
                Active       = true,
                Email        = SecurityTestData.User.Email,
                PasswordHash = HashService.Hash64(SecurityTestData.User.CorrectPassword)
            }
                );

            dataContext.Sessions.Add(
                Session = new InMemorySession
            {
                User      = User,
                ExpiresOn = DateTime.UtcNow.AddDays(1)
            });

            return(new AddressBookContactsService(
                       new InMemoryAddressBookContactsDataService(dataContext),
                       new SecurityService(
                           new InMemoryUserDataService(dataContext),
                           new InMemorySessionDataService(dataContext),
                           HashService,
                           new UserRegistrationValidator()
                           )
                       ));
        }
Beispiel #2
0
        public void CanLogOnWithCorrectModel()
        {
            DataContext.Users.Add(
                new InMemoryUser
            {
                Active       = true,
                Name         = UserName,
                Email        = UserEmail,
                PasswordHash = HashService.Hash64(UserPassword)
            });

            var client  = new HttpClient(Server);
            var request = CreatePost(
                "api/LogOn/",
                new UserLogOn
            {
                Email    = UserEmail,
                Password = UserPassword
            });

            using (var response = client.SendAsync(request).Result)
            {
                Assert.Equal(HttpStatusCode.Accepted, response.StatusCode);
                Assert.NotNull(response.Content);
                var guid = response.Content.ReadAsAsync <Guid>().Result;

                Assert.NotEqual(Guid.Empty, guid);
            }

            request.Dispose();
        }
        protected override ISecurityService GetSecurityService()
        {
            var userBuilder = new Builder <IUser>(Mock.Of <IUser>)
                              .With(u =>
            {
                u.Email        = SecurityTestData.User.Email;
                u.PasswordHash = HashService.Hash64(SecurityTestData.User.CorrectPassword);
                u.Active       = true;
            });

            var user         = userBuilder.Build();
            var inactiveUser = userBuilder
                               .Build(u =>
            {
                u.Email  = SecurityTestData.User.InactiveEmail;
                u.Active = false;
            });

            return(new SecurityService(
                       new UserDataServiceBuilder()
                       .WithUser(user)
                       .WithUser(inactiveUser)
                       .Build(),
                       new SessionDataServiceBuilder()
                       .Build(),
                       HashService,
                       new UserRegistrationValidator()
                       ));
        }
Beispiel #4
0
        protected override IAddressBookContactsService GetContactsService(
            EFDataContext dataContext,
            ref IEnumerable <IAddressBookContact> contacts)
        {
            if (contacts != null)
            {
                foreach (var contact in contacts)
                {
                    dataContext.Contacts.Add(contact.Map());
                }
            }

            contacts = dataContext.Contacts;

            var user = new EFUser
            {
                Email        = UserBuilder.UserEmail,
                PasswordHash = HashService.Hash64(UserBuilder.CorrectPassword)
            };

            User = user;
            dataContext.Users.Add(user);

            var session = new EFSession
            {
                Identifier = Guid.NewGuid(),
                User       = user,
                CreatedOn  = DateTime.UtcNow,
                ExpiresOn  = DateTime.UtcNow.AddDays(1)
            };

            Session = session;
            dataContext.Sessions.Add(session);

            dataContext.CommitAsync().Wait();

            return(new AddressBookContactsService(
                       new EFAddressBookContactsDataService(dataContext),
                       new SecurityService(
                           new EFUserDataService(dataContext),
                           new EFSessionDataService(dataContext),
                           HashService,
                           new UserRegistrationValidator()
                           )
                       ));
        }
        protected override IAddressBookContactsService GetContactsService(
            IDataContext dataContext, ref IEnumerable <IAddressBookContact> contacts)
        {
            var userBuilder = new Builder <IUser>(Mock.Of <IUser>)
                              .With(u =>
            {
                u.Active       = true;
                u.Email        = SecurityTestData.User.Email;
                u.PasswordHash = HashService.Hash64(SecurityTestData.User.CorrectPassword);
            });

            User = userBuilder.Build();

            Session = new Builder <ISession>(Mock.Of <ISession>)
                      .Build(
                s =>
            {
                s.User      = User;
                s.ExpiresOn = DateTime.UtcNow.AddDays(1);
            });

            var dataServiceBuider = new AddressBookContactsDataServiceBuilder();

            if (contacts != null)
            {
                dataServiceBuider.WithContacts(contacts);
            }
            contacts = dataServiceBuider.Contacts;

            return(new AddressBookContactsService(
                       dataServiceBuider.Build(),
                       new SecurityService(
                           new UserDataServiceBuilder()
                           .WithUser(User)
                           .Build(),
                           new SessionDataServiceBuilder()
                           .WithSession(Session)
                           .Build(),
                           HashService,
                           new UserRegistrationValidator()
                           )
                       ));
        }