public static LightPayContext PopulateContextWithAccountParams(string databaseName) { var options = GetOptions(databaseName); var context = new LightPayContext(options); var client = new Client() { Name = "Hrisi" }; context.Clients.AddAsync(client); context.Accounts.Add(new Account() { AccountNumber = "1234567890", Nickname = "1234567890", Balance = 3000000, ClientId = client.Id, CreatedOn = DateTime.Now }); context.Accounts.Add(new Account() { AccountNumber = "1245373456", Nickname = "1245373456", Balance = 150000, ClientId = client.Id, CreatedOn = DateTime.Now }); context.Accounts.Add(new Account() { AccountNumber = "1999999456", Nickname = "1999999456", Balance = 70000, ClientId = client.Id, CreatedOn = DateTime.Now }); context.SaveChanges(); return(context); }
public static LightPayContext PopulateContextWithAdmin(string databaseName) { var options = GetOptions(databaseName); var context = new LightPayContext(options); context.Administrators.AddAsync(new Administrator { Username = "******", Password = "******" }); context.SaveChanges(); return(context); }
public async Task Failed_WhenNameExist() { TestUtils.PopulateContextWithClientParams(nameof(Failed_WhenNameExist)); using (var assertContext = new LightPayContext( TestUtils.GetOptions(nameof(Failed_WhenNameExist)))) { var sut = new ClientService(assertContext); //Assert await Assert.ThrowsExceptionAsync <ArgumentException>( async() => await sut.RegisterClientAsync("Telerik")); } }
public async Task Succeed_WhenDataIsValid() { using (var assertContext = new LightPayContext( TestUtils.GetOptions(nameof(Succeed_WhenDataIsValid)))) { var sut = new UserService(assertContext); //Act var user = await sut.CreateUserAsync("Mike", "Mike246@", "Mickael"); //Assert Assert.AreSame("Mike", user.Username); } }
public async Task Succeed_WhenNameIsValid() { using (var assertContext = new LightPayContext( TestUtils.GetOptions(nameof(Succeed_WhenNameIsValid)))) { var sut = new ClientService(assertContext); //Act var registerClient = await sut.RegisterClientAsync("FirstTest"); //Assert Assert.AreSame("FirstTest", registerClient.Name); } }
public async Task Succeed_Get_Account() { TestUtils.PopulateContextWithAccountParams(nameof(Succeed_Get_Account)); using (var assertContext = new LightPayContext( TestUtils.GetOptions(nameof(Succeed_Get_Account)))) { var sut = new AccountService(assertContext); //Act Account account = await sut.GetAccount("1234567890"); //Assert Assert.AreSame("1234567890", account.Nickname); } }
public async Task GetAccount_Succeed_WhenAccountExist() { TestUtils.PopulateContextWithAccountParams(nameof(GetAccount_Succeed_WhenAccountExist)); using (var assertContext = new LightPayContext( TestUtils.GetOptions(nameof(GetAccount_Succeed_WhenAccountExist)))) { var sut = new AccountService(assertContext); //Act var account = await sut.GetAccount("1234567890"); //Assert Assert.AreEqual(3000000, account.Balance); } }
public async Task Succeed_WhenAccountExist() { TestUtils.PopulateContextWithAccountParams(nameof(Succeed_WhenAccountExist)); using (var assertContext = new LightPayContext( TestUtils.GetOptions(nameof(Succeed_WhenAccountExist)))) { var sut = new AccountService(assertContext); //Act var accountName = await sut.RenameAccountAsync("1999999456", "Test"); //Assert Assert.AreSame("Test", accountName.Nickname); } }
public async Task Succeed_GetAccountsAsync() { TestUtils.PopulateContextWithAccountParams(nameof(Succeed_GetAccountsAsync)); using (var assertContext = new LightPayContext( TestUtils.GetOptions(nameof(Succeed_GetAccountsAsync)))) { var sut = new AccountService(assertContext); //Act var accounts = await sut.GetAccountsAsync(); //Assert Assert.AreEqual(3, accounts.Count); } }
public async Task Succeed_WhenClientExist() { TestUtils.PopulateContextWithClientParams(nameof(Succeed_WhenClientExist)); using (var assertContext = new LightPayContext( TestUtils.GetOptions(nameof(Succeed_WhenClientExist)))) { var sut = new ClientService(assertContext); //Act var registerClient = await sut.GetClientsAsync(); //Assert Assert.AreEqual(registerClient.Count, 2); } }
public static LightPayContext PopulateContextWithUsers(string databaseName) { var options = GetOptions(databaseName); var context = new LightPayContext(options); context.Users.Add(new User() { Name = "Mickael", Username = "******", Password = "******" }); context.Users.Add(new User() { Name = "Jack", Username = "******", Password = "******" }); context.SaveChanges(); return(context); }
public static LightPayContext PopulateContextWithClientParams(string databaseName) { var options = GetOptions(databaseName); var context = new LightPayContext(options); context.Clients.Add(new Client() { Name = "Telerik" }); context.Clients.Add(new Client() { Name = "Dior" }); context.SaveChanges(); return(context); }
public async Task GetUsersAsync_Succeed_WhenUserExist() { TestUtils.PopulateContextWithUsers(nameof(GetUsersAsync_Succeed_WhenUserExist)); using (var assertContext = new LightPayContext( TestUtils.GetOptions(nameof(GetUsersAsync_Succeed_WhenUserExist)))) { var sut = new UserService(assertContext); //Act var users = await sut.GetUsersAsync(); //Assert Assert.AreSame("Mickael", users[0].Name); /*await Assert.ThrowsExceptionAsync<ArgumentException>( * async () => await sut.MakePayment("1234567890", 500, "1245373456","test", false));*/ } }
public async Task Failed_WhenAdminNotExist() { /*using (var arrangeContext = new LightPayContext( * TestUtils.GetOptions(nameof(Succeed_WhenAdminExist)))) * { * arrangeContext.Administrators.Add(new Administrator { Username = "******", Password = "******"}); * * arrangeContext.SaveChanges(); * }*/ TestUtils.PopulateContextWithAdmin(nameof(Failed_WhenAdminNotExist)); using (var assertContext = new LightPayContext( TestUtils.GetOptions(nameof(Failed_WhenAdminNotExist)))) { var sut = new AdministratorService(assertContext); //Assert await Assert.ThrowsExceptionAsync <ArgumentException>( async() => await sut.GetAdminAsync("Telerik", "abs")); } }
public AdministratorService(LightPayContext context) { this.context = context ?? throw new ArgumentNullException(nameof(context)); }
public ClientService(LightPayContext context) { this.context = context ?? throw new ArgumentNullException(nameof(context)); }
public UserService(LightPayContext context) { this.context = context; }