public void RemoveCompanyRoleState_Succeeds() { var companyGuid = Guid.NewGuid(); const string companyName = "Cool Company"; var roleGuid = Guid.NewGuid(); const string roleName = "Software Developer 2"; var inMemoryDatabaseBuilder = new InMemoryDatabaseBuilder(); var options = inMemoryDatabaseBuilder .WithCompanyState(companyGuid, companyName) .WithCompanyRoleState(roleGuid, roleName, companyGuid) .Build("GetCompanyState", true); // Run the test against a clean instance of the context using (var context = new MainContext(options)) { inMemoryDatabaseBuilder.InitializeContext(context); var sut = new MainRepository(context); sut.RemoveRoleFromCompanyState(companyGuid, roleGuid); var companyState = sut.GetCompanyState(companyGuid); var roleState = companyState.CompanyRoleStates.SingleOrDefault(w => w.Guid == roleGuid); roleState = context.CompanyRoleStates.Find(roleGuid); Assert.Equal(EntityState.Deleted, context.Entry(roleState).State); Assert.Equal(roleName, roleState.Name); } }
public void CanDeleteCompanyState() { var guid = Guid.NewGuid(); var name = "To be deleted."; var inMemoryDatabaseBuilder = new InMemoryDatabaseBuilder(); var options = inMemoryDatabaseBuilder.WithCompanyState(guid, name).Build("DeleteCompanyState", true); // Run the test against a clean instance of the context using (var context = new MainContext(options)) { inMemoryDatabaseBuilder.InitializeContext(context); var sut = new MainRepository(context); var state = context.CompanyStates.Find(guid); Assert.Equal(EntityState.Unchanged, context.Entry(state).State); sut.DeleteCompanyState(guid); Assert.Equal(EntityState.Deleted, context.Entry(state).State); } }
public void GetCompanyState_Succeeds_OnlyWhenGuidMatchesExisting() { var guid = Guid.NewGuid(); var invalidGuid = Guid.NewGuid(); const string name = "Cool Company"; var inMemoryDatabaseBuilder = new InMemoryDatabaseBuilder(); var options = inMemoryDatabaseBuilder.WithCompanyState(guid, name).Build("GetCompanyState"); // Run the test against a clean instance of the context using (var context = new MainContext(options)) { inMemoryDatabaseBuilder.InitializeContext(context); var sut = new MainRepository(context); var state = sut.GetCompanyState(guid); var invalidState = sut.GetCompanyState(invalidGuid); Assert.Equal(name, state.Name); Assert.Null(invalidState); } }
public void AddCompanyRoleState_Succeeds_WithNewRole_AndCreatesRoleState() { var companyGuid = Guid.NewGuid(); const string companyName = "Cool Company"; var roleGuid = Guid.NewGuid(); const string roleName = "Tester"; var inMemoryDatabaseBuilder = new InMemoryDatabaseBuilder(); var options = inMemoryDatabaseBuilder .WithCompanyState(companyGuid, companyName) .Build("GetCompanyState", true); // Run the test against a clean instance of the context using (var context = new MainContext(options)) { inMemoryDatabaseBuilder.InitializeContext(context); var sut = new MainRepository(context); sut.AddRoleToCompanyState(companyGuid, roleGuid, roleName); var companyState = sut.GetCompanyState(companyGuid); var roleState = companyState.CompanyRoleStates.Single(w => w.Guid == roleGuid); Assert.Equal(EntityState.Added, context.Entry(roleState).State); Assert.Equal(roleName, roleState.Name); } }