Exemple #1
0
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var customer = MockCustomerFactory.CreateRandom();

            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.Is <GetCustomerByIdParam>(p => p.CustomerId == customer.Id)))
            .ReturnsAsync(customer);
            _container.Use(mockedCustomerRepository);

            var expectedStatus = TestingExtensions.GetRandomEnum <MyAccountStatus>();
            var param          = new GetUpdateAccountViewModelParam
            {
                Status      = expectedStatus,
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = customer.Id,
                ReturnUrl   = GetRandom.WwwUrl(),
                Scope       = GetRandom.String(32)
            };
            var customerViewService = _container.CreateInstance <CustomerViewService>();

            //Act
            var viewModel = await customerViewService.GetUpdateAccountViewModelAsync(param);

            //Assert
            viewModel.Should().NotBeNull("This view model should never be null");
            viewModel.Status.Should().Be(expectedStatus.ToString("G"), "Because we render the status as a string for HBS message switch");
            viewModel.ReturnUrl.Should().Be(param.ReturnUrl);
            viewModel.Email.Should().Be(customer.Email);
            viewModel.FirstName.Should().Be(customer.FirstName);
            viewModel.LastName.Should().Be(customer.LastName);
        }
        public async Task WHEN_calling_with_valid_parameters_SHOULD_return_the_created_user()
        {
            //Arrange
            var expectedCustomer = MockCustomerFactory.CreateRandom();
            var sut = _container.CreateInstance <MembershipViewService>();

            sut.Membership = _container.Get <IMembershipProxy>();

            _container.GetMock <ICustomerRepository>()
            .Setup(p => p.CreateUserAsync(It.IsNotNull <CreateUserParam>()))
            .ReturnsAsync(expectedCustomer);

            //Act
            var result = await sut.RegisterAsync(new CreateUserParam
            {
                Email            = expectedCustomer.Email,
                FirstName        = expectedCustomer.FirstName,
                LastName         = expectedCustomer.LastName,
                Username         = expectedCustomer.Username,
                Password         = GetRandom.String(32),
                PasswordQuestion = GetRandom.String(32),
                PasswordAnswer   = GetRandom.String(32),
                CultureInfo      = CultureInfo.GetCultureInfo(expectedCustomer.Language),
                Scope            = GetRandom.String(32)
            });

            //Assert
            result.Status.Should().Be(MyAccountStatus.Success.ToString());
            result.FirstName.Should().BeEquivalentTo(expectedCustomer.FirstName);
            result.LastName.Should().BeEquivalentTo(expectedCustomer.LastName);
        }
        public async Task WHEN_passing_empty_PasswordAnswer_SHOULD_succeed(string passwordAnswer)
        {
            //Arrange
            var expectedCustomer = MockCustomerFactory.CreateRandom();
            var sut = _container.CreateInstance <MembershipViewService>();

            sut.Membership = _container.Get <IMembershipProxy>();

            _container.GetMock <ICustomerRepository>()
            .Setup(p => p.CreateUserAsync(It.Is <CreateUserParam>(param => string.IsNullOrWhiteSpace(param.PasswordAnswer))))
            .ReturnsAsync(expectedCustomer);

            //Act
            var result = await sut.RegisterAsync(new CreateUserParam
            {
                Email            = GetRandom.Email(),
                FirstName        = GetRandom.FirstName(),
                LastName         = GetRandom.LastName(),
                Username         = GetRandom.Email(),
                Password         = GetRandom.String(32),
                PasswordQuestion = GetRandom.String(32),
                PasswordAnswer   = passwordAnswer,
                CultureInfo      = TestingExtensions.GetRandomCulture(),
                Scope            = GetRandom.String(32)
            });

            //Assert
            result.Status.Should().Be(MyAccountStatus.Success.ToString());
        }
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var customer = MockCustomerFactory.CreateRandom();

            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.Is <GetCustomerByIdParam>(p => p.CustomerId == customer.Id)))
            .ReturnsAsync(customer);
            _container.Use(mockedCustomerRepository);

            var param = new GetAccountHeaderViewModelParam
            {
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = customer.Id,
                Scope       = GetRandom.String(32)
            };

            var customerViewService = _container.CreateInstance <CustomerViewService>();

            //Act
            var viewModel = await customerViewService.GetAccountHeaderViewModelAsync(param);

            //Assert
            viewModel.Should().NotBeNull("This view model should never be null");
            viewModel.FirstName.Should().Be(customer.FirstName);
            viewModel.LastName.Should().Be(customer.LastName);
        }
        public async Task WHEN_passing_empty_PasswordAnswer_SHOULD_succeed(string passwordAnswer)
        {
            //Arrange
            var expectedCustomer   = MockCustomerFactory.CreateRandom();
            var customerRepository = _container.CreateInstance <CustomerRepository>();

            _container.GetMock <IOvertureClient>()
            .Setup(p => p.SendAsync(It.Is <CreateCustomerMembershipRequest>(param => string.IsNullOrWhiteSpace(param.PasswordAnswer))))
            .ReturnsAsync(expectedCustomer);

            //Act
            var result = await customerRepository.CreateUserAsync(new CreateUserParam
            {
                Email            = GetRandom.Email(),
                FirstName        = GetRandom.FirstName(),
                LastName         = GetRandom.LastName(),
                Username         = GetRandom.Email(),
                Password         = GetRandom.String(32),
                PasswordQuestion = GetRandom.String(32),
                PasswordAnswer   = passwordAnswer,
                CultureInfo      = TestingExtensions.GetRandomCulture(),
                Scope            = GetRandom.String(32)
            });

            //Assert
            result.Id.Should().Be(expectedCustomer.Id);
        }
        public async Task WHEN_creating_with_requiresapproval_SHOULD_succeed()
        {
            //Arrange
            var expectedCustomer   = MockCustomerFactory.CreateRandom(AccountStatus.RequiresApproval);
            var expectedPassword   = GetRandom.String(32);
            var customerRepository = _container.CreateInstance <CustomerRepository>();

            _container.GetMock <IOvertureClient>()
            .Setup(r => r.SendAsync(It.Is <CreateCustomerMembershipRequest>(
                                        param => param.Email == expectedCustomer.Email &&
                                        param.Username == expectedCustomer.Username &&
                                        param.FirstName == expectedCustomer.FirstName &&
                                        param.LastName == expectedCustomer.LastName &&
                                        param.Password == expectedPassword)))
            .ReturnsAsync(expectedCustomer);

            //Act
            var result = await customerRepository.CreateUserAsync(
                new CreateUserParam
            {
                CultureInfo      = TestingExtensions.GetRandomCulture(),
                Username         = expectedCustomer.Username,
                Email            = expectedCustomer.Email,
                FirstName        = expectedCustomer.FirstName,
                LastName         = expectedCustomer.LastName,
                Password         = expectedPassword,
                PasswordAnswer   = GetRandom.String(70),
                PasswordQuestion = GetRandom.String(70),
                Scope            = GetRandom.String(32)
            }
                );

            //Assert
            result.Id.Should().Be(expectedCustomer.Id);
        }
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var customer = MockCustomerFactory.CreateRandom();

            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>()))
            .ReturnsAsync(customer);
            _container.Use(mockedCustomerRepository);

            var customerViewService = _container.CreateInstance <CustomerAddressViewService>();

            //Act
            var param = new GetCreateAddressViewModelAsyncParam
            {
                Scope       = GetRandom.String(32),
                CustomerId  = Guid.NewGuid(),
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CountryCode = GetRandom.String(2),
            };

            var viewModel = await customerViewService.GetCreateAddressViewModelAsync(param);

            //Assert
            viewModel.Should().NotBeNull("This view model should never be null");
            viewModel.CountryCode.ShouldBeEquivalentTo(param.CountryCode);
            viewModel.FirstName.ShouldBeEquivalentTo(customer.FirstName);
            viewModel.LastName.ShouldBeEquivalentTo(customer.LastName);
            viewModel.PhoneNumber.ShouldBeEquivalentTo(customer.PhoneNumber);
        }
Exemple #8
0
        public async Task WHEN_valid_request_SHOULD_succeed()
        {
            //Arrange
            var expectedCustomer    = MockCustomerFactory.CreateRandom();
            var expectedOldPassword = GetRandom.String(32);
            var membershipService   = _container.CreateInstance <MembershipViewService>();

            _container.GetMock <ICustomerRepository>()
            .Setup(r => r.GetCustomerByIdAsync(It.Is <GetCustomerByIdParam>(param => param.CustomerId == expectedCustomer.Id)))
            .ReturnsAsync(expectedCustomer);

            _container.GetMock <ICustomerRepository>()
            .Setup(r => r.ChangePasswordAsync(
                       It.Is <string>(username => username == expectedCustomer.Username),
                       It.IsAny <string>(),
                       It.Is <string>(oldPassword => oldPassword == expectedOldPassword),
                       It.IsAny <string>()))
            .Returns(Task.FromResult(false));

            //Act
            var result = await membershipService.ChangePasswordAsync(new ChangePasswordParam
            {
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = expectedCustomer.Id,
                Scope       = GetRandom.String(32),
                NewPassword = GetRandom.String(32),
                OldPassword = expectedOldPassword
            });

            //Assert
            result.Status.Should().Be(MyAccountStatus.Success.ToString());
            result.FirstName.Should().Be(expectedCustomer.FirstName);
        }
Exemple #9
0
        public async Task WHEN_valid_request_SHOULD_succeed()
        {
            //Arrange
            var expectedTicket    = GetRandom.String(1024);
            var expectedCustomer  = MockCustomerFactory.CreateRandom();
            var membershipService = _container.CreateInstance <MembershipViewService>();

            _container.GetMock <ICustomerRepository>()
            .Setup(r => r.GetCustomerByTicketAsync(It.Is <string>(ticket => ticket == expectedTicket)))
            .ReturnsAsync(expectedCustomer);

            _container.GetMock <ICustomerRepository>()
            .Setup(r => r.ResetPasswordAsync(
                       It.Is <string>(username => username == expectedCustomer.Username),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <string>()))
            .Returns(Task.FromResult(false));

            //Act
            var result = await membershipService.ResetPasswordAsync(
                new ResetPasswordParam
            {
                CultureInfo    = TestingExtensions.GetRandomCulture(),
                Ticket         = expectedTicket,
                Scope          = GetRandom.String(32),
                NewPassword    = GetRandom.String(32),
                PasswordAnswer = GetRandom.String(70)
            }
                );

            //Assert
            result.Status.Should().Be(MyAccountStatus.Success.ToString());
        }
Exemple #10
0
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var customer = MockCustomerFactory.CreateRandom();

            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>())).ReturnsAsync(customer);
            mockedCustomerRepository.Setup(r => r.UpdateUserAsync(It.IsAny <UpdateUserParam>())).ReturnsAsync(customer);

            _container.Use(mockedCustomerRepository);

            var customerViewService = _container.CreateInstance <CustomerViewService>();

            //Act
            var viewModel = await customerViewService.UpdateAccountAsync(new UpdateAccountParam
            {
                ReturnUrl         = GetRandom.String(32),
                Scope             = GetRandom.String(32),
                CustomerId        = Guid.NewGuid(),
                CultureInfo       = TestingExtensions.GetRandomCulture(),
                Email             = GetRandom.String(32),
                FirstName         = GetRandom.String(32),
                LastName          = GetRandom.String(32),
                PreferredLanguage = GetRandom.String(4),
            });

            //Assert
            viewModel.Should().NotBeNull();
            viewModel.FirstName.Should().Be(customer.FirstName);
        }
Exemple #11
0
        public void WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var expectedStatus = TestingExtensions.GetRandomEnum <MyAccountStatus>();
            var param          = new GetLoginViewModelParam
            {
                Status            = expectedStatus,
                CultureInfo       = TestingExtensions.GetRandomCulture(),
                Customer          = MockCustomerFactory.CreateRandom(),
                ReturnUrl         = GetRandom.WwwUrl(),
                LoginUrl          = GetRandom.WwwUrl(),
                CreateAccountUrl  = GetRandom.WwwUrl(),
                ForgotPasswordUrl = GetRandom.WwwUrl(),
                Username          = GetRandom.String(32)
            };
            var membershipViewService = _container.CreateInstance <MembershipViewService>();

            membershipViewService.Membership = _container.Get <IMembershipProxy>();

            //Act
            var viewModel = membershipViewService.GetLoginViewModel(param);

            //Assert
            viewModel.Should().NotBeNull("This view model should never be null");
            viewModel.Status.Should().Be(expectedStatus.ToString("G"), "Because we render the status as a string for HBS message switch");
            viewModel.ReturnUrl.Should().Be(param.ReturnUrl);
            viewModel.CreateAccountUrl.Should().Be(param.CreateAccountUrl);
            viewModel.ForgotPasswordUrl.Should().Be(param.ForgotPasswordUrl);
            viewModel.LoginUrl.Should().Be(param.LoginUrl);
            viewModel.FirstName.Should().Be(param.Customer.FirstName);
            viewModel.LastName.Should().Be(param.Customer.LastName);
        }
Exemple #12
0
        public async Task WHEN_Status_is_NULL_SHOULD_create_view_model_with_empty_status(MyAccountStatus?status)
        {
            //Arrange
            var customer = MockCustomerFactory.CreateRandom();

            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.Is <GetCustomerByIdParam>(p => p.CustomerId == customer.Id)))
            .ReturnsAsync(customer);
            _container.Use(mockedCustomerRepository);

            var param = new GetUpdateAccountViewModelParam
            {
                Status      = status,
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = customer.Id,
                ReturnUrl   = GetRandom.WwwUrl(),
                Scope       = GetRandom.String(32)
            };
            var customerViewService = _container.CreateInstance <CustomerViewService>();

            //Act
            var viewModel = await customerViewService.GetUpdateAccountViewModelAsync(param);

            //Assert
            viewModel.Status.Should().BeEmpty();
        }
Exemple #13
0
        public async Task WHEN_valid_request_SHOULD_succeed()
        {
            //Arrange
            var expectedTicket     = GetRandom.String(1024);
            var expectedCustomer   = MockCustomerFactory.CreateRandom();
            var customerRepository = _container.CreateInstance <CustomerRepository>();

            _container.GetMock <IOvertureClient>()
            .Setup(r => r.SendAsync(It.Is <GetCustomerFromPasswordTicketRequest>(param => param.Ticket == expectedTicket)))
            .ReturnsAsync(expectedCustomer);

            //Act
            var result = await customerRepository.GetCustomerByTicketAsync(expectedTicket);

            //Assert
            result.Id.Should().Be(expectedCustomer.Id);
        }
Exemple #14
0
        public async Task WHEN_requesting_to_log_in_valid_user_response_SHOULD_have_correct_user_id()
        {
            //Arrange
            var expectedCustomer = MockCustomerFactory.CreateRandom();
            var sut = _container.CreateInstance <MembershipViewService>();

            sut.Membership = _container.Get <IMembershipProxy>();

            _container.GetMock <IMembershipProxy>()
            .Setup(p => p.LoginUser(It.IsNotNull <string>(), It.IsNotNull <string>()))
            .Returns(true);

            _container.GetMock <IMembershipProxy>()
            .Setup(p => p.GetUser(It.IsNotNull <string>(), It.IsNotNull <bool>()))
            .Returns(MockMembershipUser(
                         GetRandom.Email(),
                         expectedCustomer.Id,
                         GetRandom.Email(),
                         GetRandom.String(32),
                         GetRandom.String(32),
                         true,
                         false,
                         GetRandom.DateTime(),
                         GetRandom.DateTime(),
                         GetRandom.DateTime(),
                         GetRandom.DateTime(),
                         GetRandom.DateTime()
                         ));

            _container.GetMock <ICustomerRepository>()
            .Setup(p => p.GetCustomerByIdAsync(It.Is <GetCustomerByIdParam>(param => param.CustomerId == expectedCustomer.Id)))
            .ReturnsAsync(expectedCustomer);

            //Act
            var result = await sut.LoginAsync(new LoginParam()
            {
                CultureInfo = TestingExtensions.GetRandomCulture(),
                Password    = GetRandom.String(15),
                Username    = GetRandom.Email(),
                Scope       = GetRandom.String(32)
            });

            //Assert
            result.Status.Should().Be(MyAccountStatus.Success.ToString());
        }
Exemple #15
0
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var customer = MockCustomerFactory.CreateRandom();
            var address  = MockAddressFactory.CreateRandom();

            customer.AddressIds = new List <Guid>
            {
                address.Id
            };

            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>()))
            .ReturnsAsync(customer);
            _container.Use(mockedCustomerRepository);

            var mockedAddressRepository = new Mock <IAddressRepository>();

            mockedAddressRepository.Setup(r => r.GetAddressByIdAsync(It.IsAny <Guid>()))
            .ReturnsAsync(address);
            _container.Use(mockedAddressRepository);


            var customerViewService = _container.CreateInstance <CustomerAddressViewService>();

            //Act
            var param = new GetEditAddressViewModelAsyncParam
            {
                Scope       = GetRandom.String(32),
                CustomerId  = Guid.NewGuid(),
                CultureInfo = TestingExtensions.GetRandomCulture(),
                AddressId   = address.Id,
            };

            var viewModel = await customerViewService.GetEditAddressViewModelAsync(param);

            //Assert
            viewModel.Should().NotBeNull();
            viewModel.FirstName.ShouldBeEquivalentTo(address.FirstName);
            viewModel.LastName.ShouldBeEquivalentTo(address.LastName);
            viewModel.PhoneNumber.ShouldBeEquivalentTo(address.PhoneNumber);
            viewModel.PhoneRegex.Should().NotBeNull();
            viewModel.PostalCodeRegex.Should().NotBeNull();
        }
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var address  = MockAddressFactory.CreateRandom();
            var customer = MockCustomerFactory.CreateRandom();

            customer.Addresses = new List <Address>
            {
                address
            };

            var mockedCustomerAddressRepository = new Mock <ICustomerAddressRepository>();

            mockedCustomerAddressRepository.Setup(r => r.GetCustomerAddressesAsync(It.IsAny <Guid>(), It.IsAny <string>()))
            .ReturnsAsync(new List <Address> {
                address
            });
            _container.Use(mockedCustomerAddressRepository);

            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>()))
            .ReturnsAsync(customer);
            _container.Use(mockedCustomerRepository);

            var customerViewService = _container.CreateInstance <CustomerAddressViewService>();

            //Act
            var param = new GetAddressListViewModelParam
            {
                Scope              = GetRandom.String(32),
                CustomerId         = Guid.NewGuid(),
                CultureInfo        = TestingExtensions.GetRandomCulture(),
                AddAddressUrl      = GetRandom.String(32),
                EditAddressBaseUrl = GetRandom.String(32),
                CountryCode        = GetRandom.String(32)
            };

            var viewModel = await customerViewService.GetAddressListViewModelAsync(param);

            //Assert
            viewModel.Should().NotBeNull("This view model should never be null");
            viewModel.AddAddressUrl.ShouldBeEquivalentTo(param.AddAddressUrl);
            viewModel.Addresses.First().AddressName.ShouldBeEquivalentTo(address.AddressName);
        }
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var address  = MockAddressFactory.CreateRandom();
            var customer = MockCustomerFactory.CreateRandom();

            customer.AddressIds = new List <Guid>
            {
                address.Id
            };

            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>())).ReturnsAsync(customer);
            _container.Use(mockedCustomerRepository);

            var mockedCustomerAddressRepository = new Mock <ICustomerAddressRepository>();

            mockedCustomerAddressRepository.Setup(r => r.UpdateAddressAsync(It.IsAny <Guid>(), It.IsAny <Address>())).ReturnsAsync(address);
            _container.Use(mockedCustomerAddressRepository);

            var mockedAddressRepository = new Mock <IAddressRepository>();

            mockedAddressRepository.Setup(r => r.GetAddressByIdAsync(It.IsAny <Guid>())).ReturnsAsync(address);
            _container.Use(mockedAddressRepository);

            var customerViewService = _container.CreateInstance <CustomerAddressViewService>();

            //Act
            var param = new EditAddressParam
            {
                Scope       = GetRandom.String(32),
                CustomerId  = Guid.NewGuid(),
                CultureInfo = TestingExtensions.GetRandomCulture(),
                AddressId   = address.Id,
                ReturnUrl   = GetRandom.String(32),
                EditAddress = new EditAddressRequest()
            };

            var viewModel = await customerViewService.UpdateAddressAsync(param);

            //Assert
            viewModel.Should().NotBeNull();
            viewModel.Status.ShouldBeEquivalentTo(MyAccountStatus.Success.ToString());
        }
Exemple #18
0
        public void WHEN_CultureInfo_is_Empty_SHOULD_throw_ArgumentException(CultureInfo cultureInfo)
        {
            //Arrange
            var membershipViewService = _container.CreateInstance <MembershipViewService>();
            var param = new GetLoginViewModelParam
            {
                Status      = TestingExtensions.GetRandomEnum <MyAccountStatus>(),
                CultureInfo = cultureInfo,
                Customer    = MockCustomerFactory.CreateRandom(),
                ReturnUrl   = GetRandom.WwwUrl()
            };

            //Act
            var ex = Assert.Throws <ArgumentException>(() => membershipViewService.GetLoginViewModel(param));

            //Assert
            ex.Message.Should().ContainEquivalentOf("CultureInfo");
        }
        public async Task WHEN_address_does_not_belong_to_the_customer_SHOULD_return_null()
        {
            //Arrange
            var address  = MockAddressFactory.CreateRandom();
            var customer = MockCustomerFactory.CreateRandom();

            customer.AddressIds = new List <Guid>
            {
                //no address
            };

            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>())).ReturnsAsync(customer);
            _container.Use(mockedCustomerRepository);

            var mockedCustomerAddressRepository = new Mock <ICustomerAddressRepository>();

            mockedCustomerAddressRepository.Setup(r => r.UpdateAddressAsync(It.IsAny <Guid>(), It.IsAny <Address>())).ReturnsAsync(address);
            _container.Use(mockedCustomerAddressRepository);

            var mockedAddressRepository = new Mock <IAddressRepository>();

            mockedAddressRepository.Setup(r => r.GetAddressByIdAsync(It.IsAny <Guid>())).ReturnsAsync(address);
            _container.Use(mockedAddressRepository);

            var customerViewService = _container.CreateInstance <CustomerAddressViewService>();

            //Act
            var param = new EditAddressParam
            {
                Scope       = GetRandom.String(32),
                CustomerId  = Guid.NewGuid(),
                CultureInfo = TestingExtensions.GetRandomCulture(),
                AddressId   = address.Id,
                ReturnUrl   = GetRandom.String(32),
                EditAddress = new EditAddressRequest()
            };

            var viewModel = await customerViewService.UpdateAddressAsync(param);

            //Assert
            viewModel.Should().BeNull();
        }
Exemple #20
0
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var customer = MockCustomerFactory.CreateRandom();
            var expectedPasswordLength   = GetRandom.PositiveInt();
            var expectedPasswordNonAlpha = GetRandom.PositiveInt();

            var param = new GetCustomerChangePasswordViewModelParam
            {
                CultureInfo = TestingExtensions.GetRandomCulture(),
                Scope       = GetRandom.String(32),
                CustomerId  = customer.Id,
            };
            var membershipViewService = _container.CreateInstance <MembershipViewService>();

            membershipViewService.Membership = _container.Get <IMembershipProxy>();

            _container.GetMock <MembershipProvider>()
            .SetupGet(m => m.MinRequiredPasswordLength)
            .Returns(expectedPasswordLength)
            .Verifiable();

            _container.GetMock <MembershipProvider>()
            .SetupGet(m => m.MinRequiredNonAlphanumericCharacters)
            .Returns(expectedPasswordNonAlpha)
            .Verifiable("Regex must be based on this value");

            var customerRepository = new Mock <ICustomerRepository>();

            customerRepository.Setup(r => r.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>()))
            .ReturnsAsync(customer);

            //Act
            var viewModel = await membershipViewService.GetChangePasswordViewModelAsync(param);

            //Assert
            viewModel.Should().NotBeNull("This view model should never be null");
            viewModel.MinRequiredPasswordLength.Should().Be(expectedPasswordLength);
            viewModel.MinRequiredNonAlphanumericCharacters.Should().Be(expectedPasswordNonAlpha);
            viewModel.PasswordRegexPattern.Should().NotBeNull();

            _container.GetMock <IMembershipProxy>().VerifyAll();
        }
Exemple #21
0
        public void WHEN_Status_is_NULL_SHOULD_create_view_model_with_empty_status(MyAccountStatus?status)
        {
            //Arrange
            var param = new GetLoginViewModelParam
            {
                Status      = status,
                CultureInfo = TestingExtensions.GetRandomCulture(),
                Customer    = MockCustomerFactory.CreateRandom(),
                ReturnUrl   = GetRandom.WwwUrl(),
                Username    = GetRandom.String(32)
            };
            var membershipViewService = _container.CreateInstance <MembershipViewService>();

            //Act
            var viewModel = membershipViewService.GetLoginViewModel(param);

            //Assert
            viewModel.Status.Should().BeEmpty();
        }
        public async Task WHEN_valid_request_SHOULD_succeed()
        {
            //Arrange
            var expectedCustomer   = MockCustomerFactory.CreateRandom();
            var customerRepository = _container.CreateInstance <CustomerRepository>();

            _container.GetMock <IOvertureClient>()
            .Setup(r => r.SendAsync(It.IsAny <UpdateCustomerRequest>()))
            .ReturnsAsync(expectedCustomer);

            //Act
            var result = await customerRepository.UpdateUserAsync(
                new UpdateUserParam
            {
                Customer = expectedCustomer,
                Scope    = GetRandom.String(32)
            }
                );

            //Assert
            result.Id.Should().Be(expectedCustomer.Id);
        }
Exemple #23
0
        public async Task WHEN_Membership_Accept_Empty_PasswordAnsnwer_SHOULD_succeed(string passwordAnswer)
        {
            //Arrange
            var membershipService = _container.CreateInstance <MembershipViewService>();

            membershipService.Membership = _container.Get <IMembershipProxy>();

            _container.GetMock <MembershipProvider>()
            .SetupGet(p => p.RequiresQuestionAndAnswer)
            .Returns(false);

            _container.GetMock <ICustomerRepository>()
            .Setup(r => r.GetCustomerByTicketAsync(It.IsAny <string>()))
            .ReturnsAsync(MockCustomerFactory.CreateRandom());

            _container.GetMock <ICustomerRepository>()
            .Setup(r => r.ResetPasswordAsync(
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.IsAny <string>(),
                       It.Is <string>(pa => pa == passwordAnswer)))
            .Returns(Task.FromResult(false));

            //Act
            var result = await membershipService.ResetPasswordAsync(
                new ResetPasswordParam
            {
                CultureInfo    = TestingExtensions.GetRandomCulture(),
                Ticket         = GetRandom.String(1024),
                Scope          = GetRandom.String(32),
                NewPassword    = GetRandom.String(32),
                PasswordAnswer = passwordAnswer
            }
                );

            //Assert
            result.Status.Should().Be(MyAccountStatus.Success.ToString());
        }
Exemple #24
0
        public async Task WHEN_valid_request_SHOULD_return_customer()
        {
            //Arrange
            var expectedCustomer    = MockCustomerFactory.CreateRandom();
            var expectedScope       = GetRandom.String(32);
            var expectedCultureInfo = TestingExtensions.GetRandomCulture();
            var customerRepository  = _container.CreateInstance <CustomerRepository>();

            _container.GetMock <IOvertureClient>()
            .Setup(r => r.SendAsync(It.Is <GetCustomerRequest>(
                                        param => param.CustomerId == expectedCustomer.Id)))
            .ReturnsAsync(expectedCustomer);

            //3.8 upgrade
            _container.GetMock <ICacheProvider>()
            .Setup(provider => provider.GetOrAddAsync(
                       It.IsNotNull <CacheKey>(),
                       It.IsNotNull <Func <Task <Customer> > >(),
                       It.IsAny <Func <Customer, Task> >(),
                       It.IsAny <CacheKey>()))
            .Returns <CacheKey, Func <Task <Customer> >, Func <Customer, Task>, CacheKey>(
                (key, func, arg3, arg4) => func())
            .Verifiable("This value must be proprelly cached by Id");

            //Act
            var customer = await customerRepository.GetCustomerByIdAsync(new GetCustomerByIdParam
            {
                CustomerId  = expectedCustomer.Id,
                Scope       = expectedScope,
                CultureInfo = expectedCultureInfo
            });

            //Assert
            customer.Should().NotBeNull();
            customer.Id.Should().Be(expectedCustomer.Id);

            _container.GetMock <ICacheProvider>().VerifyAll();
        }