Пример #1
0
        public async Task CreateAsync_WithValidModel_ShouldReturnTrue_And_InsertInDatabase()
        {
            // Arrange
            var dbCount = this.dbContext.Accounts.Count();

            await this.SeedUserAsync();

            var model = new CardCreateServiceModel
            {
                Name       = SampleName,
                UserId     = SampleUserId,
                AccountId  = SampleAccountId,
                ExpiryDate = SampleExpiryDate
            };

            // Act
            var result = await this.cardService.CreateAsync(model);

            // Assert
            result
            .Should()
            .BeTrue();

            this.dbContext
            .Cards
            .Should()
            .HaveCount(dbCount + 1);
        }
Пример #2
0
        public async Task <bool> CreateAsync(CardCreateServiceModel model)
        {
            if (!this.IsEntityStateValid(model) ||
                !this.Context.Users.Any(u => u.Id == model.UserId))
            {
                return(false);
            }

            string generatedNumber;
            string generated3DigitSecurityCode;

            do
            {
                generatedNumber             = this.cardHelper.Generate16DigitNumber();
                generated3DigitSecurityCode = this.cardHelper.Generate3DigitSecurityCode();
            } while (await this.Context.Cards.AnyAsync(a => a.Number == generatedNumber && a.SecurityCode == generated3DigitSecurityCode));

            var dbModel = Mapper.Map <Card>(model);

            dbModel.Number       = generatedNumber;
            dbModel.SecurityCode = generated3DigitSecurityCode;

            await this.Context.Cards.AddAsync(dbModel);

            await this.Context.SaveChangesAsync();

            return(true);
        }
Пример #3
0
        public async Task CreateAsync_WithInvalidExpiryDate_Should_ReturnFalse(string expiryDate)
        {
            // Set invalid expiryDate
            var model = new CardCreateServiceModel
            {
                Name       = SampleName,
                UserId     = SampleUserId,
                AccountId  = SampleAccountId,
                ExpiryDate = expiryDate
            };

            // Act
            var result = await this.cardService.CreateAsync(model);

            // Assert
            result
            .Should()
            .BeFalse();
        }
Пример #4
0
        public async Task CreateAsync_WithInvalidName_Should_ReturnFalse()
        {
            // Set invalid name
            var model = new CardCreateServiceModel
            {
                Name       = new string('m', ModelConstants.Card.NameMaxLength + 1),
                UserId     = SampleUserId,
                AccountId  = SampleAccountId,
                ExpiryDate = SampleExpiryDate
            };

            // Act
            var result = await this.cardService.CreateAsync(model);

            // Assert
            result
            .Should()
            .BeFalse();
        }
Пример #5
0
        public async Task CreateAsync_WithInvalidExpiryDate_Should_Not_InsertInDatabase(string expiryDate)
        {
            // Set invalid expiryDate
            var model = new CardCreateServiceModel
            {
                Name       = SampleName,
                UserId     = SampleUserId,
                AccountId  = SampleAccountId,
                ExpiryDate = expiryDate
            };

            // Act
            await this.cardService.CreateAsync(model);

            // Assert
            this.dbContext
            .Cards
            .Should()
            .BeEmpty();
        }
Пример #6
0
        public async Task CreateAsync_WithInvalidName_Should_Not_InsertInDatabase()
        {
            // Set invalid name
            var model = new CardCreateServiceModel
            {
                Name       = new string('m', ModelConstants.Card.NameMaxLength + 1),
                UserId     = SampleUserId,
                AccountId  = SampleAccountId,
                ExpiryDate = SampleExpiryDate
            };

            // Act
            await this.cardService.CreateAsync(model);

            // Assert
            this.dbContext
            .Cards
            .Should()
            .BeEmpty();
        }
Пример #7
0
        public async Task CreateAsync_WithValidModel_Should_ReturnTrue()
        {
            // Arrange
            await this.SeedUserAsync();

            var model = new CardCreateServiceModel
            {
                Name       = SampleName,
                UserId     = SampleUserId,
                AccountId  = SampleAccountId,
                ExpiryDate = SampleExpiryDate
            };

            // Act
            var result = await this.cardService.CreateAsync(model);

            // Assert
            result
            .Should()
            .BeTrue();
        }