コード例 #1
0
        public async void LastName_Create_length()
        {
            Mock <ICustomerRepository> customerRepository = new Mock <ICustomerRepository>();

            customerRepository.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Customer()));

            var validator = new ApiCustomerRequestModelValidator(customerRepository.Object);
            await validator.ValidateCreateAsync(new ApiCustomerRequestModel());

            validator.ShouldHaveValidationErrorFor(x => x.LastName, new string('A', 129));
        }
コード例 #2
0
        public async void StoreID_Create_Valid_Reference()
        {
            Mock <ICustomerRepository> customerRepository = new Mock <ICustomerRepository>();

            customerRepository.Setup(x => x.StoreByStoreID(It.IsAny <int>())).Returns(Task.FromResult <Store>(new Store()));

            var validator = new ApiCustomerRequestModelValidator(customerRepository.Object);
            await validator.ValidateCreateAsync(new ApiCustomerRequestModel());

            validator.ShouldNotHaveValidationErrorFor(x => x.StoreID, 1);
        }
コード例 #3
0
        private async void BeUniqueByAccountNumber_Create_Not_Exists()
        {
            Mock <ICustomerRepository> customerRepository = new Mock <ICustomerRepository>();

            customerRepository.Setup(x => x.ByAccountNumber(It.IsAny <string>())).Returns(Task.FromResult <Customer>(null));
            var validator = new ApiCustomerRequestModelValidator(customerRepository.Object);

            await validator.ValidateCreateAsync(new ApiCustomerRequestModel());

            validator.ShouldNotHaveValidationErrorFor(x => x.AccountNumber, "A");
        }
コード例 #4
0
        public async void AccountNumber_Create_null()
        {
            Mock <ICustomerRepository> customerRepository = new Mock <ICustomerRepository>();

            customerRepository.Setup(x => x.Get(It.IsAny <int>())).Returns(Task.FromResult(new Customer()));

            var validator = new ApiCustomerRequestModelValidator(customerRepository.Object);
            await validator.ValidateCreateAsync(new ApiCustomerRequestModel());

            validator.ShouldHaveValidationErrorFor(x => x.AccountNumber, null as string);
        }
コード例 #5
0
        public async void TerritoryID_Create_Invalid_Reference()
        {
            Mock <ICustomerRepository> customerRepository = new Mock <ICustomerRepository>();

            customerRepository.Setup(x => x.SalesTerritoryByTerritoryID(It.IsAny <int>())).Returns(Task.FromResult <SalesTerritory>(null));

            var validator = new ApiCustomerRequestModelValidator(customerRepository.Object);

            await validator.ValidateCreateAsync(new ApiCustomerRequestModel());

            validator.ShouldHaveValidationErrorFor(x => x.TerritoryID, 1);
        }