Exemple #1
0
        public void WHEN_Status_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string status)
        {
            var service = _container.CreateInstance <CartService>();
            var param   = new UpdateCartViewModelParam
            {
                CultureInfo     = TestingExtensions.GetRandomCulture(),
                CustomerId      = GetRandom.Guid(),
                CartName        = GetRandom.String(32),
                BaseUrl         = GetRandom.String(32),
                Shipments       = new List <Shipment>(),
                BillingCurrency = GetRandom.String(32),
                CartType        = GetRandom.String(32),
                Coupons         = new List <Coupon>(),
                Customer        = new CustomerSummary(),
                OrderLocation   = new OrderLocationSummary(),
                Scope           = GetRandom.String(32),
                Status          = status
            };

            // Act
            var exception = Assert.ThrowsAsync <ArgumentException>(() => service.UpdateCartAsync(param));

            //Assert
            exception.ParamName.Should().BeSameAs("param");
            exception.Message.Should().Contain("Status");
        }
        public async Task WHEN_passing_empty_username_SHOULD_fallback_to_email_as_username(string username)
        {
            //Arrange
            var sut = _container.CreateInstance <MembershipViewService>();

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

            var expectedEmail = GetRandom.Email();

            _container.GetMock <ICustomerRepository>()
            .Setup(p => p.CreateUserAsync(It.Is <CreateUserParam>(param => string.IsNullOrWhiteSpace(param.Username))))
            .ReturnsAsync(new Customer
            {
                Email    = expectedEmail,
                Username = expectedEmail
            });

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

            //Assert
            result.Status.Should().Be(MyAccountStatus.Success.ToString());
            result.Username.Should().BeEquivalentTo(expectedEmail);
        }
        public void WHEN_creating_user_fails_SHOULD_not_attempt_to_merge_cart()
        {
            //Arrange
            var sut = _container.CreateInstance <MembershipViewService>();

            _container.GetMock <ICustomerRepository>()
            .Setup(p => p.CreateUserAsync(It.IsAny <CreateUserParam>()))
            .Throws(new ComposerException(GetRandom.String(3)));

            //Act and Assert
            Assert.ThrowsAsync <ComposerException>(() => 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   = GetRandom.String(32),
                CultureInfo      = TestingExtensions.GetRandomCulture(),
                Scope            = GetRandom.String(32),
            }));

            _container.GetMock <ICartMergeProvider>().Verify(provider => provider.MergeCartAsync(It.IsAny <CartMergeParam>()), Times.Never);
        }
Exemple #4
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);
        }
        public void When_Passing_null_Scope_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var paymentMethods = new List <PaymentMethod> {
                new PaymentMethod()
            };

            MockFindCartPaymentMethodsRequest(paymentMethods);

            var repository = _container.CreateInstance <PaymentRepository>();
            var param      = new GetPaymentMethodsParam
            {
                CartName      = GetRandom.String(32),
                CultureInfo   = TestingExtensions.GetRandomCulture(),
                ProviderNames = new List <string> {
                    GetRandom.String(7), GetRandom.String(7)
                },
                Scope = null,
            };

            // Act
            var exception = Assert.ThrowsAsync <ArgumentException>(() => repository.GetPaymentMethodsAsync(param));

            //Assert
            exception.ParamName.Should().BeSameAs("param");
            exception.Message.Should().Contain("Scope");
        }
Exemple #6
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);
        }
        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);
        }
Exemple #8
0
        public void WHEN_Customer_is_Null_SHOULD_create_view_model_with_empty_bag()
        {
            //Arrange
            var expectedStatus = TestingExtensions.GetRandomEnum <MyAccountStatus>();
            var param          = new GetLoginViewModelParam
            {
                Status            = expectedStatus,
                CultureInfo       = TestingExtensions.GetRandomCulture(),
                Customer          = null,
                ReturnUrl         = GetRandom.WwwUrl(),
                Username          = GetRandom.String(32),
                ForgotPasswordUrl = GetRandom.WwwUrl(),
                CreateAccountUrl  = GetRandom.WwwUrl(),
                LoginUrl          = GetRandom.WwwUrl(),
            };
            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.Bag.Should().BeEmpty("No PropertyBag to load from");
        }
Exemple #9
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 #10
0
        public void When_Passing_null_CartName_SHOULD_throw_ArgumentException()
        {
            //Arrange
            var overtureClient = new Mock <IOvertureClient>();

            var fulfillmentMethods = new List <FulfillmentMethod> {
                new FulfillmentMethod()
            };

            overtureClient.Setup(client => client.SendAsync(It.IsNotNull <FindCalculatedFulfillmentMethodsRequest>()))
            .ReturnsAsync(fulfillmentMethods)
            .Verifiable();

            _container.Use(overtureClient);

            var repository = _container.CreateInstance <FulfillmentMethodRepository>();
            var param      = new GetShippingMethodsParam
            {
                CartName    = null,
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = GetRandom.Guid(),
                Scope       = GetRandom.String(32),
            };

            // Act
            var exception = Assert.ThrowsAsync <ArgumentException>(() => repository.GetCalculatedFulfillmentMethods(param));

            //Assert
            exception.ParamName.Should().BeSameAs("param");
            exception.Message.Should().Contain("CartName");
        }
        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);
        }
Exemple #12
0
        public async Task When_Overture_Return_Empty_List_SHOULD_Not_Throw()
        {
            //Arrange
            var overtureClient = new Mock <IOvertureClient>();

            var fulfillmentMethods = new List <FulfillmentMethod> {
                null
            };

            overtureClient.Setup(client => client.SendAsync(It.IsNotNull <FindCalculatedFulfillmentMethodsRequest>()))
            .ReturnsAsync(fulfillmentMethods)
            .Verifiable();

            _container.Use(overtureClient);

            //Act
            var param = new GetShippingMethodsParam
            {
                CartName    = GetRandom.String(32),
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = GetRandom.Guid(),
                Scope       = GetRandom.String(32),
            };

            var repository = _container.CreateInstance <FulfillmentMethodRepository>();
            var result     = await repository.GetCalculatedFulfillmentMethods(param).ConfigureAwait(false);

            //Assert
            result.Should().NotBeNull();
        }
        public async Task WHEN_passing_valid_arguments_SHOULD_create_viewmodel()
        {
            //Arrange
            var address = MockAddressFactory.CreateRandom();

            var mockedCustomerAddressRepository = new Mock <ICustomerAddressRepository>();

            mockedCustomerAddressRepository.Setup(r => r.CreateAddressAsync(It.IsAny <Guid>(), It.IsAny <Address>(),
                                                                            It.IsAny <string>()))
            .ReturnsAsync(address);

            _container.Use(mockedCustomerAddressRepository);

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

            //Act
            var viewModel = await customerViewService.CreateAddressAsync(new CreateAddressParam
            {
                ReturnUrl   = GetRandom.String(32),
                Scope       = GetRandom.String(32),
                CustomerId  = Guid.NewGuid(),
                CultureInfo = TestingExtensions.GetRandomCulture(),
                EditAddress = new EditAddressRequest()
            });

            //Assert
            viewModel.Should().NotBeNull("This view model should never be null");
            viewModel.FirstName.Should().Be(address.FirstName);
        }
Exemple #14
0
        public async Task WHEN_Dependencies_Return_NullValues_SHOULD_Succeed()
        {
            var service = _container.CreateInstance <CartService>();

            _container.Use(CartRepositoryFactory.CreateWithNullValues());

            // Act
            var result = await service.UpdateCartAsync(new UpdateCartViewModelParam
            {
                CultureInfo     = TestingExtensions.GetRandomCulture(),
                CustomerId      = GetRandom.Guid(),
                CartName        = GetRandom.String(32),
                BaseUrl         = GetRandom.String(32),
                Shipments       = new List <Shipment>(),
                BillingCurrency = GetRandom.String(32),
                CartType        = GetRandom.String(32),
                Coupons         = new List <Coupon>(),
                Customer        = new CustomerSummary(),
                OrderLocation   = new OrderLocationSummary(),
                Scope           = GetRandom.String(32),
                Status          = GetRandom.String(32)
            });

            // Assert
            result.Should().NotBeNull();
        }
Exemple #15
0
        public async Task WHEN_requesting_to_log_in_valid_user_response_but_user_is_null_THEN_response_SHOULD_be_unsuccessfull()
        {
            //Arrange
            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 <MembershipUser>(null);

            //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.Failed.ToString());
        }
Exemple #16
0
        public void WHEN_Scope_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope)
        {
            // Arrange
            _container.Use(OvertureClientFactory.Create());
            var repository = _container.CreateInstance <CartRepository>();
            var param      = new UpdateLineItemParam
            {
                ScopeId     = null,
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = GetRandom.Guid(),
                CartName    = GetRandom.String(32),
                LineItemId  = GetRandom.Guid(),
                Quantity    = GetRandom.PositiveInt(),
                GiftMessage = GetRandom.String(32),
                GiftWrap    = GetRandom.Boolean(),
            };

            // Act
            Expression <Func <Task <ProcessedCart> > > expression = () => repository.UpdateLineItemAsync(param);
            var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke());

            //Assert
            exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name);
            exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.ScopeId)));
        }
        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);
        }
        public void WHEN_Passing_Valid_Parameters_SHOULD_Succeed()
        {
            //Arrange
            _container.Use(ViewModelMapperFactory.Create());
            _container.Use(CountryRepositoryFactory.Create());

            var localizationProviderMock = new Mock <ILocalizationProvider>();

            localizationProviderMock
            .Setup(c => c.GetLocalizedString(It.IsAny <GetLocalizedParam>())).Returns("{0}");

            _container.Use(localizationProviderMock);

            var service = _container.CreateInstance <CountryService>();

            // Act
            var result = service.RetrieveRegionsAsync(new RetrieveCountryParam
            {
                IsoCode     = GetRandom.String(32),
                CultureInfo = TestingExtensions.GetRandomCulture(),
            }).Result;

            // Assert
            result.Should().NotBeNull();
        }
        public async Task WHEN_passing_empty_username_SHOULD_fallback_to_email_as_username(string username)
        {
            //Arrange
            var customerRepository = _container.CreateInstance <CustomerRepository>();

            var expectedEmail = GetRandom.Email();

            _container.GetMock <IOvertureClient>()
            .Setup(r => r.SendAsync(It.Is <CreateCustomerMembershipRequest>(param => string.IsNullOrWhiteSpace(param.Username))))
            .ReturnsAsync(new Customer
            {
                Id            = GetRandom.Guid(),
                Email         = expectedEmail,
                Username      = expectedEmail,
                AccountStatus = AccountStatus.Active
            });

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

            //Assert
            result.Email.Should().BeEquivalentTo(expectedEmail);
            result.Username.Should().BeEquivalentTo(expectedEmail);
        }
Exemple #20
0
        public async Task WHEN_param_ok_SHOULD_invoke_LineItemService_GetInvalidLineItems()
        {
            //Arrange
            var p = new RemoveInvalidLineItemsParam
            {
                CartName          = GetRandom.String(7),
                CultureInfo       = TestingExtensions.GetRandomCulture(),
                CustomerId        = GetRandom.Guid(),
                Scope             = GetRandom.String(7),
                ExecuteWorkflow   = GetRandom.Boolean(),
                WorkflowToExecute = GetRandom.String(7),
                BaseUrl           = GetRandom.WwwUrl()
            };

            MockLineItemService(GetRandom.Boolean());

            Container.GetMock <ICartRepository>().Setup(repository => repository.RemoveLineItemsAsync(It.IsAny <RemoveLineItemsParam>())).ReturnsAsync(new ProcessedCart()).Verifiable();

            var sut = Container.CreateInstance <CartService>();

            //Act
            await sut.RemoveInvalidLineItemsAsync(p);

            //Assert
            Container.Verify <ILineItemService>(m => m.GetInvalidLineItems(It.IsNotNull <ProcessedCart>()));
        }
        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 void WHEN_Scope_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string scope)
        {
            var service = _container.CreateInstance <CartService>();

            var param = new UpdateLineItemParam
            {
                ScopeId     = scope,
                CultureInfo = TestingExtensions.GetRandomCulture(),
                CustomerId  = GetRandom.Guid(),
                CartName    = GetRandom.String(32),
                LineItemId  = GetRandom.Guid(),
                GiftMessage = GetRandom.String(32),
                GiftWrap    = GetRandom.Boolean(),
                Quantity    = GetRandom.PositiveInt(),
                BaseUrl     = GetRandom.String(32)
            };

            // Act
            Expression <Func <Task <CartViewModel> > > expression = () => service.UpdateLineItemAsync(param);
            var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke());

            //Assert
            exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name);
            exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.ScopeId)));
        }
Exemple #23
0
        public async Task WHEN_customer_not_exist_SHOULD_return_null()
        {
            //Arrange
            var mockedCustomerRepository = new Mock <ICustomerRepository>();

            mockedCustomerRepository.Setup(r => r.GetCustomerByIdAsync(It.IsAny <GetCustomerByIdParam>()))
            .ReturnsAsync(null);

            _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().BeNull();
        }
Exemple #24
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();
        }
        public async Task When_Overture_Return_Empty_List_SHOULD_Not_Throw()
        {
            //Arrange
            var paymentMethods = new List <PaymentMethod> {
                new PaymentMethod()
            };

            MockFindCartPaymentMethodsRequest(paymentMethods);

            //Act
            var param = new GetPaymentMethodsParam
            {
                CartName      = GetRandom.String(32),
                CultureInfo   = TestingExtensions.GetRandomCulture(),
                ProviderNames = new List <string> {
                    GetRandom.String(7), GetRandom.String(7)
                },
                Scope = GetRandom.String(32),
            };

            var repository = _container.CreateInstance <PaymentRepository>();
            var result     = await repository.GetPaymentMethodsAsync(param).ConfigureAwait(false);

            //Assert
            result.Should().NotBeNull();
        }
Exemple #26
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_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());
        }
Exemple #28
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());
        }
        public void WHEN_passing_empty_email_SHOULD_throw_ArgumentException(string email)
        {
            //Arrange
            var sut = _container.CreateInstance <MembershipViewService>();

            sut.Membership = _container.Get <IMembershipProxy>();
            var param = new CreateUserParam
            {
                Email            = email,
                FirstName        = GetRandom.FirstName(),
                LastName         = GetRandom.LastName(),
                Username         = GetRandom.Email(),
                Password         = GetRandom.String(32),
                PasswordQuestion = GetRandom.String(32),
                PasswordAnswer   = GetRandom.String(32),
                CultureInfo      = TestingExtensions.GetRandomCulture(),
                Scope            = GetRandom.String(32)
            };

            // Act
            var exception = Assert.ThrowsAsync <ArgumentException>(() => sut.RegisterAsync(param));

            //Assert
            exception.Message.Should().Contain("Email");
        }
Exemple #30
0
        public void WHEN_Status_Is_NullOrWhitespace_SHOULD_Throw_ArgumentException(string status)
        {
            var service = _container.CreateInstance <CartService>();
            var param   = new UpdateCartViewModelParam
            {
                CultureInfo     = TestingExtensions.GetRandomCulture(),
                CustomerId      = GetRandom.Guid(),
                CartName        = GetRandom.String(32),
                BaseUrl         = GetRandom.String(32),
                Shipments       = new List <Shipment>(),
                BillingCurrency = GetRandom.String(32),
                CartType        = GetRandom.String(32),
                Coupons         = new List <Coupon>(),
                Customer        = new CustomerSummary(),
                OrderLocation   = new OrderLocationSummary(),
                Scope           = GetRandom.String(32),
                Status          = status
            };

            // Act
            Expression <Func <Task <CartViewModel> > > expression = () => service.UpdateCartAsync(param);
            var exception = Assert.ThrowsAsync <ArgumentException>(() => expression.Compile().Invoke());

            //Assert
            exception.ParamName.Should().BeEquivalentTo(GetParamsInfo(expression)[0].Name);
            exception.Message.Should().StartWith(GetMessageOfNullWhiteSpace(nameof(param.Status)));
        }