public async Task ReturnCardNumberDto_WhenValidId()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCardNumberDto_WhenValidId")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            var user = new User();
            var card = new BankCard()
            {
                Id     = 1,
                Number = "1111111111111111"
            };
            CardNumberDto result;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.CardService(bedeSlotsContext, userManager);
                await bedeSlotsContext.BankCards.AddAsync(card);

                await bedeSlotsContext.SaveChangesAsync();

                result = await sut.GetCardNumberByIdAsync(card.Id);
            }

            Assert.IsTrue(result.Number == card.Number.Substring(12));
            Assert.IsInstanceOfType(result, typeof(CardNumberDto));
        }
Example #2
0
        public async Task AddCardToDatabase_WhenValidParametersArePassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "RemoveCarSuccessfully_WhenValidParamatersArePassed").Options;

            string   userId        = "test";
            string   cvvNumber     = "123";
            string   number        = "1616161616161616";
            CardType type          = CardType.Visa;
            DateTime createdOn     = DateTime.Now;
            DateTime expiryDate    = DateTime.Parse("11-11-2111");
            string   cardholerName = "test";

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.CardService(bedeSlotsContext, userManager);
                await sut.AddCardAsync(number, cardholerName, cvvNumber, expiryDate, type, userId);
            }

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                Assert.IsTrue(await bedeSlotsContext.BankCards.CountAsync() == 1);
                Assert.IsTrue(await bedeSlotsContext.BankCards.AnyAsync(c => c.Number == number));
            }
        }
Example #3
0
        public async Task ReturnTrue_WhenCardExistsInDatabase()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnTrue_WhenCardExistsInDatabase")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            var user = new User();
            var card = new BankCard();

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                await bedeSlotsContext.BankCards.AddAsync(card);

                await bedeSlotsContext.SaveChangesAsync();
            }

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.CardService(bedeSlotsContext, userManager);

                Assert.IsTrue(sut.CardExists(card.Id));
            }
        }
Example #4
0
        public async Task ReturnEmptyCollectionOfCardNumberAssociatedWithUserId_WhenValidUserIdIsPassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            ICollection <CardNumberDto> cards;

            Data.CardService cardService;

            var user = new User();
            var card = new BankCard()
            {
                UserId    = user.Id,
                CvvNumber = "123",
                Number    = "1616161616161616",
                Type      = CardType.Visa
            };

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCollectionOfCardNumberAssociatedWithUserId_WhenValidUserIdIsPassed")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.Users.Add(user);
                bedeSlotsContext.SaveChanges();
            }
            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                cardService = new Data.CardService(bedeSlotsContext, userManager);
                cards       = await cardService.GetUserCardsAllNumbersAsync(user.Id);

                Assert.IsTrue(cards.Count == 0);
            }
        }
Example #5
0
        public void NotThrowException_WhenValidParametersArePassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var bedeSlotsContext = new BedeSlotsDbContext(new Microsoft.EntityFrameworkCore.DbContextOptions <BedeSlotsDbContext>());

            var sut = new Data.CardService(bedeSlotsContext, userManager);
        }
Example #6
0
        public async Task ThrowServiceException_WhenNullParameterIsPassed()
        {
            var userStoreMock  = new Mock <IUserStore <User> >();
            var userManager    = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);
            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ThrowServiceException_WhenNullParameterIsPassed").UseInternalServiceProvider(serviceProvider)
                                 .Options;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var cardService = new Data.CardService(bedeSlotsContext, userManager);
                await Assert.ThrowsExceptionAsync <ServiceException>(async() => await cardService.GetUserCardsAsync(null));
            }
        }
Example #7
0
        public async Task ThrowArgumentException_WhenNotExistingUserIdIsPassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            Data.CardService cardService;

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ThrowArgumentException_WhenNotExistingUserIdIsPassed")
                                 .UseInternalServiceProvider(serviceProvider).Options;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                cardService = new Data.CardService(bedeSlotsContext, userManager);
                await Assert.ThrowsExceptionAsync <ArgumentException>(async() => await cardService.GetUserCardsLastNumbersAsync("not existing user id"));
            }
        }
Example #8
0
        public async Task SetCardsIsDeletedPropertyToTrue_WhenValidIsPassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "SetCardsIsDeletedPropertyToTrue_WhenValidIsPassed")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            var user      = new User();
            var firstCard = new BankCard()
            {
                UserId    = user.Id,
                User      = user,
                CvvNumber = "123",
                Number    = "1616161616161616",
                Type      = CardType.Visa,
                CreatedOn = DateTime.Now
            };
            var secondCard = new BankCard()
            {
                UserId    = user.Id,
                CvvNumber = "123",
                Number    = "6161616161616161",
                Type      = CardType.Visa,
                CreatedOn = DateTime.Now
            };

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                await bedeSlotsContext.BankCards.AddAsync(firstCard);

                await bedeSlotsContext.SaveChangesAsync();

                var sut = new Data.CardService(bedeSlotsContext, userManager);

                await sut.DeleteCardAsync(firstCard.Id);
            }
            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                Assert.IsTrue(await bedeSlotsContext.BankCards.AnyAsync(x => x.IsDeleted == true));
            }
        }
Example #9
0
        public void ReturnFalse_WhenCardExistsInDatabase()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var notExistingCardId = 1;

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnFalse_WhenCardExistsInDatabase")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.CardService(bedeSlotsContext, userManager);

                Assert.IsFalse(sut.CardExists(notExistingCardId));
            }
        }
Example #10
0
        public async Task ReturnCardById_WhenValidIdIsPassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCardById_WhenValidIdIsPassed").UseInternalServiceProvider(serviceProvider)
                                 .Options;

            Data.CardService cardService;

            var user = new User();
            var card = new BankCard()
            {
                UserId    = user.Id,
                User      = user,
                CvvNumber = "123",
                Number    = "1616161616161616",
                Type      = CardType.Visa,
                CreatedOn = DateTime.Now
            };

            BankCard result;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                cardService = new Data.CardService(bedeSlotsContext, userManager);
                await bedeSlotsContext.BankCards.AddAsync(card);

                await bedeSlotsContext.SaveChangesAsync();

                result = await cardService.GetCardByIdAsync(card.Id);
            }

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                Assert.IsTrue(result.Id == card.Id);
            }
        }
Example #11
0
        public async Task ReturnCollectionOfCardNumbersLastFourDigitsInDatabase_WhenValidUserIdIsPassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            ICollection <CardNumberDto> cards;

            Data.CardService cardService;

            var user = new User();
            var card = new BankCard()
            {
                UserId    = user.Id,
                CvvNumber = "123",
                Number    = "1616161616161616",
                Type      = CardType.Visa
            };

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCollectionOfCardNumbersLastFourDigitsInDatabase_WhenValidUserIdIsPassed").UseInternalServiceProvider(serviceProvider)
                                 .Options;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                bedeSlotsContext.BankCards.Add(card);
                bedeSlotsContext.Users.Add(user);
                bedeSlotsContext.SaveChanges();

                cardService = new Data.CardService(bedeSlotsContext, userManager);
                cards       = await cardService.GetUserCardsLastNumbersAsync(user.Id);
            }
            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                Assert.IsTrue(cards.Count == 1);
                Assert.IsInstanceOfType(cards, typeof(ICollection <CardNumberDto>));
                Assert.IsTrue(cards.First().Number == card.Number.Substring(12));
            }
        }
Example #12
0
        public async Task ReturnCardDetailsDto_WhenValidIdIsPassed()
        {
            var userStoreMock = new Mock <IUserStore <User> >();
            var userManager   = new UserManager <User>(userStoreMock.Object, null, null, null, null, null, null, null, null);

            var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>()
                                 .UseInMemoryDatabase(databaseName: "ReturnCardDetailsDto_WhenValidIdIsPassed")
                                 .UseInternalServiceProvider(serviceProvider)
                                 .Options;

            var user = new User();
            var card = new BankCard()
            {
                UserId    = user.Id,
                User      = user,
                CvvNumber = "123",
                Number    = "1616161616161616",
                Type      = CardType.Visa,
                CreatedOn = DateTime.Now
            };

            CardDetailsDto result;

            using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions))
            {
                var sut = new Data.CardService(bedeSlotsContext, userManager);
                await bedeSlotsContext.BankCards.AddAsync(card);

                await bedeSlotsContext.SaveChangesAsync();

                result = await sut.GetCardDetailsByIdAsync(card.Id);
            }

            Assert.IsTrue(result.LastFourDigit == card.Number.Substring(12));
            Assert.IsInstanceOfType(result, typeof(CardDetailsDto));
        }