public async Task Can_create_a_contact() { using var factory = new TestDbContextFactory(); using var context = await factory.CreateContextAsync(); var contact = new Contact { FirstName = "Albert", LastName = "Einstein", PhoneNumber = "2222-1111" }; var expected = contact.Clone(); var controller = new ContactsController(null, context); var result = await controller.Post(contact); Assert.IsType <CreatedAtActionResult>(result); var createdAtActionResult = result as CreatedAtActionResult; var actual = createdAtActionResult.Value as Contact; Assert.Equal(expected.FirstName, actual.FirstName); Assert.Equal(expected.LastName, actual.LastName); Assert.Equal(expected.PhoneNumber, actual.PhoneNumber); Assert.Single(context.Contacts, c => c.Id == expected.Id); }
public async Task Can_update_a_contact() { using var factory = new TestDbContextFactory(); using var context = await factory.CreateContextAsync(); var contact = new Contact { FirstName = "Albert", LastName = "Einstein", PhoneNumber = "2222-1111" }; await context.AddAsync(contact); await context.SaveChangesAsync(); var changedContact = contact.Clone(); changedContact.FirstName = "Ulbert"; changedContact.LastName = "Oinstein"; changedContact.PhoneNumber = "3333-4444"; var expected = changedContact.Clone(); var controller = new ContactsController(null, context); var result = await controller.Update(changedContact, changedContact.Id); Assert.IsType <NoContentResult>(result); Assert.Single(context.Contacts, c => c.Id == changedContact.Id); var actual = await context.Contacts.FindAsync(expected.Id); Assert.Equal(expected.FirstName, actual.FirstName); Assert.Equal(expected.LastName, actual.LastName); Assert.Equal(expected.PhoneNumber, actual.PhoneNumber); }
public async Task Can_get_all_contactsAsync() { using var factory = new TestDbContextFactory(); using var context = await factory.CreateContextAsync(); context.AddRange( new Contact { FirstName = "Albert", LastName = "Einstein", PhoneNumber = "2222-1111" }, new Contact { FirstName = "Marie", LastName = "Curie", PhoneNumber = "1111-1111" }); await context.SaveChangesAsync(); var controller = new ContactsController(null, context); var result = await controller.Get(); var actual = result.Value as IList <Contact>; Assert.NotNull(actual); Assert.Equal(2, actual.Count); Assert.Equal("Albert", actual[0].FirstName); Assert.Equal("Marie", actual[1].FirstName); }
public void SetUp() { _ctx = TestDbContextFactory.GetContext(); _service = new ListingsService(_ctx, MapperConfigFactory.GetMapper(), new MockCurrentUserService(), new NullLogger <ListingsService>()); _ctx.Database.EnsureDeleted(); _ctx.Database.EnsureCreated(); }
public CustomerRepositoryStub() { var factory = new TestDbContextFactory(); this.context = factory.GetContext(); factory.FillDb(TestCustomersCollection.Collection); this.dbSet = context.Set <Customer>(); }
public void SetUp() { string[] args = new string[0]; TestDbContextFactory factory = new TestDbContextFactory(); this.dbContext = factory.CreateDbContext(args); TestDbInitializer.Seed(this.dbContext); }
static void Main(string[] args) { using (var context = new TestDbContextFactory().CreateDbContext()) { // remove the Navigation Property Company on Person and the query below works. var test = context.Bases.ToList(); } }
public void TestInitialize() { var factory = new TestDbContextFactory(); this.context = factory.GetContext(); factory.FillDb(TestCustomersCollection.Collection); this.TestCustomer = TestCustomersCollection.TestCustomer; this.defaultEntityCount = TestCustomersCollection.Collection.Count(); this.repository = new Repository <Customer>(context); }
public void Init() { context = TestDbContextFactory.Build(); organization = context.Organizations.First(); expenseType = context.TransactionSubTypes.OfType <ExpenseType>().First(); var accountType = context.AccountTypes.First(); var fundType = context.FundTypes.First(); account = new SubsidiaryAccount { Id = -1, Name = "Test Account", UpdatedBy = "Foo", CreatedBy = "Foo", AccountType = accountType, Organization = organization }; fund = new SubsidiaryFund { Id = -1, Name = fundType.Name, BankNumber = "42", Code = "123", CreatedBy = "Foo", UpdatedBy = "Foo", FundType = fundType, Organization = organization }; fund.Subsidiaries.Add(account); account.Fund = fund; context.Funds.Add(fund); payee = new Payee { Name = "Test", AddressLine1 = "123 Street", City = "Foo", State = "FO", PostalCode = "98503", Organization = organization, UpdatedBy = "Foo", CreatedBy = "Foo" }; context.Payees.Add(payee); context.SaveChanges(); }
protected LocalRepoMoviesTests(IConfig config) : base() { Config = config; var contextFactory = new TestDbContextFactory(Config); DbContextScopeFactory = new DbContextScopeFactory(contextFactory); AmbientDbContextLocator = new AmbientDbContextLocator(); MovieDetailsDbAccess = new MovieDetailsDbAccess(AmbientDbContextLocator, Mapper, config); MovieListsDbAccess = new MoviesListsDbAccess(AmbientDbContextLocator, Mapper); using var context = DbContextScopeFactory.Create(); MoviesContext.Database.EnsureDeleted(); MoviesContext.Database.EnsureCreated(); }
public void Init() { principalProvider = Substitute.For <IPrincipalProvider>(); principal = Substitute.For <IPrincipal>(); principalProvider.GetCurrent().Returns(principal); principal.Identity.Name.Returns("user"); interceptor = new AuditChangeInterceptor(principalProvider) { Logger = Substitute.For <ILogger>() }; context = TestDbContextFactory.Build(interceptors: new[] { interceptor }); }
public async Task Can_delete_a_contact() { using var factory = new TestDbContextFactory(); using var context = await factory.CreateContextAsync(); var contact = new Contact { FirstName = "Albert", LastName = "Einstein", PhoneNumber = "2222-1111" }; var expected = contact.Clone(); await context.AddAsync(contact); await context.SaveChangesAsync(); var controller = new ContactsController(null, context); var result = await controller.Delete(expected.Id); Assert.IsType <NoContentResult>(result); Assert.Empty(context.Contacts); }
public void Init() { context = TestDbContextFactory.Build(); organization = context.Organizations.First(); receiptType = context.TransactionSubTypes.OfType <ReceiptType>().First(); var accountType = context.AccountTypes.First(); var fundType = context.FundTypes.First(); account = new SubsidiaryAccount { Id = -1, Name = "Test Account", UpdatedBy = "Foo", CreatedBy = "Foo", AccountType = accountType, Organization = organization }; fund = new SubsidiaryFund { Id = -1, Name = fundType.Name, BankNumber = "42", Code = "123", CreatedBy = "Foo", UpdatedBy = "Foo", FundType = fundType, Organization = organization }; fund.Subsidiaries.Add(account); account.Fund = fund; context.Funds.Add(fund); context.SaveChanges(); }
public async Task Can_get_one_contact() { using var factory = new TestDbContextFactory(); using var context = await factory.CreateContextAsync(); var contact = new Contact { FirstName = "Albert", LastName = "Einstein", PhoneNumber = "2222-1111" }; var expected = contact.Clone(); context.Add(contact); await context.SaveChangesAsync(); var controller = new ContactsController(null, context); var result = await controller.Get(expected.Id); var actual = result.Value; Assert.NotNull(actual); Assert.Equal(expected.FirstName, actual.FirstName); Assert.Equal(expected.LastName, actual.LastName); Assert.Equal(expected.PhoneNumber, actual.PhoneNumber); }
public void Init() { context = TestDbContextFactory.Build(); }
public EmployeeDataServiceTests() : base(new EmployeeDataService(TestDbContextFactory.CreateDbContext())) { }
static PlaceDataService Factory_DataService() { PlaceDataService placeDataService = new PlaceDataService(TestDbContextFactory.CreateDbContext()); return(placeDataService); }
static EmployeeDataService Factory_DataService() { EmployeeDataService employeeDataService = new EmployeeDataService(TestDbContextFactory.CreateDbContext()); return(employeeDataService); }
public void Init() { context = TestDbContextFactory.Build(); organization = context.Organizations.First(); }