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)); } }
public async Task ReturnUser_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: "ReturnUser_WhenValidIdIsPassed") .UseInternalServiceProvider(serviceProvider) .Options; var user = new User() { UserName = "******" }; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { bedeSlotsContext.Users.Add(user); bedeSlotsContext.SaveChanges(); } using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var sut = new Data.UserService(bedeSlotsContext, userManager); var result = await sut.GetUserByIdAsync(user.Id); Assert.IsTrue(result != null); } }
public async Task ReturnUserCurrency_WhenValidUserIdIsPassed() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ReturnUserCurrency_WhenValidUserIdIsPassed") .UseInternalServiceProvider(serviceProvider).Options; var user = new User() { Currency = Currency.BGN }; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { await bedeSlotsContext.Users.AddAsync(user); await bedeSlotsContext.SaveChangesAsync(); } using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var sut = new Data.CurrencyService(bedeSlotsContext); var result = await sut.GetUserCurrencyAsync(user.Id); Assert.IsTrue(result == user.Currency); Assert.IsInstanceOfType(result, typeof(Currency)); } }
public async Task ReduceUserBalance_WhenValidParametersArePassed() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ReduceUserBalance_WhenValidParametersArePassed") .UseInternalServiceProvider(serviceProvider).Options; var tenDollars = 10; var user = new User() { Balance = tenDollars + tenDollars, Currency = Currency.USD }; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { bedeSlotsContext.Users.Add(user); bedeSlotsContext.SaveChanges(); } using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var currencyConverterMock = new Mock <ICurrencyConverterService>(); var sut = new Data.UserBalanceService(bedeSlotsContext, currencyConverterMock.Object); var result = await sut.ReduceMoneyAsync(tenDollars, user.Id); Assert.IsTrue(result == tenDollars); } }
public async Task ThrowServiceException_WhenAmountParameterIsBiggerThanUserBalance() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ReduceUserBalance_WhenValidParametersArePassed") .UseInternalServiceProvider(serviceProvider).Options; var tenDollars = 10; var amountBiggerThanUserBalance = 5000; var user = new User() { Balance = tenDollars, Currency = Currency.USD }; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { bedeSlotsContext.Users.Add(user); bedeSlotsContext.SaveChanges(); } using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var currencyConverterMock = new Mock <ICurrencyConverterService>(); var sut = new Data.UserBalanceService(bedeSlotsContext, currencyConverterMock.Object); await Assert.ThrowsExceptionAsync <ServiceException>(async() => await sut.ReduceMoneyAsync(amountBiggerThanUserBalance, user.Id)); } }
public async Task ReturnUserBalance_WhenValidUserIdIsPassed() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ReturnUserBalance_WhenValidUserIdIsPassed") .UseInternalServiceProvider(serviceProvider).Options; var expectedBalance = 100; var user = new User() { Balance = expectedBalance, Currency = Currency.USD }; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { bedeSlotsContext.Users.Add(user); bedeSlotsContext.SaveChanges(); } using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var currencyConverterMock = new Mock <ICurrencyConverterService>(); var sut = new Data.UserBalanceService(bedeSlotsContext, currencyConverterMock.Object); var result = await sut.GetUserBalanceByIdAsync(user.Id); Assert.IsTrue(result == expectedBalance); } }
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)); }
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)); } }
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); } }
public async Task ReturnCollectionOfAllRoles_WhenInvoked() { 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: "ReturnCollectionOfAllRoles_WhenInvoked") .UseInternalServiceProvider(serviceProvider).Options; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var role = new IdentityRole("User"); bedeSlotsContext.Roles.Add(role); bedeSlotsContext.SaveChanges(); } using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var sut = new Data.UserService(bedeSlotsContext, userManager); var result = await sut.GetAllRolesAsync(); Assert.IsInstanceOfType(result, typeof(ICollection <IdentityRole>)); Assert.IsTrue(result.Count == 1); } }
public void ReturnEmptyCollectionUsers_WhenInvoked() { 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: "ReturnEmptyCollectionUsers_WhenInvoked") .UseInternalServiceProvider(serviceProvider).Options; var transactionServiceMock = new Mock <ITransactionService>(); using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { bedeSlotsContext.Roles.Add(new IdentityRole("User")); bedeSlotsContext.SaveChanges(); } using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var sut = new Data.UserService(bedeSlotsContext, userManager); Assert.IsTrue(sut.GetAllUsers().Count() == 0); } }
public async Task AddTransactionCorrectly_WhenValidParamentersArePassed() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "AddTransactionCorrectly_WhenValidParamentersArePassed") .UseInternalServiceProvider(serviceProvider).Options; var validTransactionType = TransactionType.Deposit; var user = new User(); string description = "test"; int validAmount = 100; var baseCurrency = Currency.USD; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var currencyConverterMock = new Mock <ICurrencyConverterService>(); var sut = new Data.TransactionService(bedeSlotsContext, currencyConverterMock.Object); currencyConverterMock.Setup((x) => x.ConvertToBaseCurrencyAsync(10, Currency.USD)).ReturnsAsync(10); await sut.AddTransactionAsync(validTransactionType, user.Id, description, validAmount, baseCurrency); } using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { Assert.IsTrue(await bedeSlotsContext.Transactions.CountAsync() == 1); Assert.IsTrue(await bedeSlotsContext.Transactions.AnyAsync(x => x.Description == description)); } }
public async Task ReturnCollectionOfAllTransaction_WhenValidParametersArePassed() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ReturnCollectionOfAllTransaction_WhenValidParametersArePassed") .UseInternalServiceProvider(serviceProvider).Options; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { bedeSlotsContext.Transactions.Add(new Transaction() { User = new User() { Email = "test" } }); bedeSlotsContext.SaveChanges(); } using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var currencyConverterMock = new Mock <ICurrencyConverterService>(); var sut = new Data.TransactionService(bedeSlotsContext, currencyConverterMock.Object); var result = sut.GetAllTransactions(); Assert.IsTrue(await result.CountAsync() == 1); } }
public async Task ReturnCollectionOfUserTransactions_WhenValidUserIdIsPassed() { var serviceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider(); var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ReturnCollectionOfUserTransactions_WhenValidUserIdIsPassed") .UseInternalServiceProvider(serviceProvider).Options; var user = new User() { Email = "test" }; var otherUser = new User(); var transaction = new Transaction() { User = user, UserId = user.Id, Type = TransactionType.Deposit }; var secondTransaction = new Transaction() { User = user, UserId = user.Id, Type = TransactionType.Deposit }; var thirdTransaction = new Transaction() { User = otherUser, UserId = otherUser.Id, Type = TransactionType.Deposit }; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { await bedeSlotsContext.Users.AddAsync(user); await bedeSlotsContext.Users.AddAsync(otherUser); await bedeSlotsContext.Transactions.AddAsync(transaction); await bedeSlotsContext.Transactions.AddAsync(secondTransaction); await bedeSlotsContext.Transactions.AddAsync(thirdTransaction); await bedeSlotsContext.SaveChangesAsync(); } using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var currencyConverterMock = new Mock <ICurrencyConverterService>(); var sut = new Data.TransactionService(bedeSlotsContext, currencyConverterMock.Object); var result = sut.GetUserTransactionsAsync(user.Id); Assert.IsTrue(await result.CountAsync() == 2); } }
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); }
public void ThrowServiceExcpetion_WhenNullCurrencyConverterParameterIsPassed() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ThrowServiceExcpetion_WhenNullCurrencyConverterParameterIsPassed") .UseInternalServiceProvider(serviceProvider).Options; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { Assert.ThrowsException <ServiceException>(() => new Data.UserBalanceService(bedeSlotsContext, null)); } }
public void ThrowServiceException_WhenNullUserManagerParameterIsPassed() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ThrowServiceException_WhenNullUserManagerParameterIsPassed").Options; var transactionServiceMock = new Mock <ITransactionService>(); using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { Assert.ThrowsException <ServiceException>(() => new Data.UserService(bedeSlotsContext, null)); } }
public async Task ThrowServiceException_WhenThereAreNoUsersInDatabase() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ThrowServiceException_WhenThereAreNoUsersInDatabase") .UseInternalServiceProvider(serviceProvider).Options; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var sut = new Data.CurrencyService(bedeSlotsContext); await Assert.ThrowsExceptionAsync <ServiceException>(async() => await sut.GetUserCurrencyAsync("test")); } }
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)); } }
public void InitializeCorrectly_WhenValidContextIsPassed() { var serviceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider(); var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "InitializeCorrectly_WhenValidContextIsPassed") .UseInternalServiceProvider(serviceProvider).Options; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var sut = new Data.CurrencyService(bedeSlotsContext); Assert.IsInstanceOfType(sut, typeof(Data.CurrencyService)); } }
public void InitializeCorrectly_WhenValidParametersArePassed() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "InitializeCorrectly_WhenValidParametersArePassed") .UseInternalServiceProvider(serviceProvider).Options; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var currencyConverterMock = new Mock <ICurrencyConverterService>(); var sut = new Data.TransactionService(bedeSlotsContext, currencyConverterMock.Object); Assert.IsInstanceOfType(sut, typeof(Data.TransactionService)); } }
public async Task ThrowServiceException_WhenNullParameterIsPassed() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ThrowServiceException_WhenNullParameterIsPassed") .UseInternalServiceProvider(serviceProvider).Options; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var currencyConverterMock = new Mock <ICurrencyConverterService>(); var sut = new Data.UserBalanceService(bedeSlotsContext, currencyConverterMock.Object); await Assert.ThrowsExceptionAsync <ServiceException>(async() => await sut.GetUserBalanceByIdInBaseCurrencyAsync(null)); } }
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 contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "NotThrowException_WhenValidParametersArePassed").Options; var transactionServiceMock = new Mock <ITransactionService>(); using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var sut = new Data.UserService(bedeSlotsContext, userManager); Assert.IsInstanceOfType(sut, typeof(Data.UserService)); } }
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")); } }
public async Task ThrowServiceException_WhenNegativeAmountParameterIsPassed() { var contextOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ThrowServiceException_WhenNegativeAmountParameterIsPassed") .UseInternalServiceProvider(serviceProvider).Options; using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var currencyConverterMock = new Mock <ICurrencyConverterService>(); decimal invalidNumber = -10; var sut = new Data.UserBalanceService(bedeSlotsContext, currencyConverterMock.Object); await Assert.ThrowsExceptionAsync <ServiceException>(async() => await sut.DepositMoneyAsync(invalidNumber, "valid id")); } }
public void ReturnCollectionOfAllCurrencies_WhenInvoked() { var serviceProvider = new ServiceCollection().AddEntityFrameworkInMemoryDatabase().BuildServiceProvider(); var contexOptions = new DbContextOptionsBuilder <BedeSlotsDbContext>() .UseInMemoryDatabase(databaseName: "ReturnCollectionOfAllCurrencies_WhenInvoked") .UseInternalServiceProvider(serviceProvider).Options; using (var bedeSlotsContext = new BedeSlotsDbContext(contexOptions)) { var sut = new Data.CurrencyService(bedeSlotsContext); var result = sut.GetAllCurrencies(); Assert.IsInstanceOfType(result, typeof(ICollection <Currency>)); Assert.IsTrue(result.Count == 4); } }
public async Task ThrowServiceException_WhenNullArgumentIsPassed() { 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_WhenNullArgumentIsPassed") .UseInternalServiceProvider(serviceProvider).Options; var transactionServiceMock = new Mock <ITransactionService>(); using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var sut = new Data.UserService(bedeSlotsContext, userManager); await Assert.ThrowsExceptionAsync <ServiceException>(async() => await sut.GetUserRoleAsync(null)); } }
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)); } }
public async Task ThrowServiceException_WhenNullUserIdIsPassed() { 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: "SuccessfullyChangeUserCurrentRole_WhenValidParametersArePassed") .UseInternalServiceProvider(serviceProvider).Options; var newRole = new IdentityRole("newRole"); using (var bedeSlotsContext = new BedeSlotsDbContext(contextOptions)) { var sut = new Data.UserService(bedeSlotsContext, userManager); await Assert.ThrowsExceptionAsync <ServiceException>(async() => await sut.EditUserRoleAsync(null, newRole.Id)); } }
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)); } }