public void InMemoryParticipantStore_canDeleteItem() { //Arrange var participant1 = new Participant(null, "Bob", "Smith"); var participant2 = new Participant(null, "John", "Doe"); var participantArray = new Participant[] { participant1, participant2 }; IRepository <Participant> store = new InMemoryParticipantStore(); participantArray = store.Add(participantArray).ToArray(); participant1 = participantArray[0]; participant2 = participantArray[1]; //Act store.Delete(participant1); //Assert var remainingParticipants = store.All(); Assert.That(remainingParticipants.Count(), Is.EqualTo(1)); var participantLeft = remainingParticipants.ToArray()[0]; // Looking for no side effects Assert.That(participantLeft.ID, Is.EqualTo(participant2.ID)); Assert.That(participantLeft.FirstName, Is.EqualTo(participant2.FirstName)); Assert.That(participantLeft.LastName, Is.EqualTo(participant2.LastName)); }
public void InMemoryParticipantStore_canUpsertMany() { var original1 = new Participant(1, "Bob", "Smith"); var original2 = new Participant(2, "Joe", "Smith"); var originalList = new List <Participant>() { original1, original2 }; IRepository <Participant> store = new InMemoryParticipantStore(originalList); var changed1 = new Participant(1, "Sarah", "Jane"); var changed2 = new Participant(2, "Jane", "Smith"); var changedList = new List <Participant>() { changed1, changed2 }; store.Add(changedList); var resultList = store.All().ToList(); Assert.That(resultList, Is.EquivalentTo(changedList)); }
public void setupParticipantThatDoesNotExists(int id, string firstName, string lastName) { var testDataStore = new InMemoryParticipantStore(); var participantControllerUnderTest = new ParticipantController(testDataStore); testContext.ParticipantControllerUnderTest = participantControllerUnderTest; testContext.TestDataStore = testDataStore; }
public void InMemoryParticipantStore_canSelectAll_NotImplemented() { //We do not need paging right now, so we just write a test to show it isn't implemented and thats expected. IRepository <Participant> store = new InMemoryParticipantStore(); TestDelegate testDelegate = () => store.All(1, 1); Assert.That(testDelegate, Throws.TypeOf <NotImplementedException>()); }
public void setupEmptyDatabase(string firstname, string lastName) { //Or just make an empty database. var testDataStore = new InMemoryParticipantStore(); var participantControllerUnderTest = new ParticipantController(testDataStore); testContext.ParticipantControllerUnderTest = participantControllerUnderTest; testContext.TestDataStore = testDataStore; }
public void InMemoryParticipantStore_canAdd() { var participantAdded = new Participant(1, "Bob", "Smith"); IRepository <Participant> store = new InMemoryParticipantStore(); store.Add(participantAdded); var resultParticipant = store.Single(a => a.ID == participantAdded.ID); Assert.That(resultParticipant, Is.EqualTo(participantAdded)); }
public void givenADatabaseWithParticipant(int id, string firstName, string lastName) { var testDataStore = new InMemoryParticipantStore(); var participantControllerUnderTest = new ParticipantController(testDataStore); var expectedParticipant = new Participant(id, firstName, lastName); testDataStore.Add(expectedParticipant); testContext.ParticipantControllerUnderTest = participantControllerUnderTest; testContext.TestDataStore = testDataStore; }
public void InMemoryParticipantStore_canUpsertAndThenSelect() { var participantAdded = new Participant(null, "Bob", "Smith"); IRepository <Participant> store = new InMemoryParticipantStore(); store.Add(participantAdded); var resultParticipant = store.Single(a => a.FirstName == participantAdded.FirstName); Assert.That(resultParticipant.FirstName, Is.EqualTo(participantAdded.FirstName)); Assert.That(resultParticipant.ID, Is.Not.Null); }
public void InMemoryParticipantStore_ConstructsWithExistingList() { //Setup List <Participant> originalList = new List <Participant>(); originalList.Add(new Participant(1, "Bob", "Smith")); originalList.Add(new Participant(2, "Joe", "Snape")); //Run test IRepository <Participant> store = new InMemoryParticipantStore(originalList); //Assert Results Assert.That(store.All().ToList(), Is.EquivalentTo(originalList)); }
public void InMemoryParticipantStore_CanLookup() { //Setup List <Participant> originalList = new List <Participant>(); var expectedParticipant = new Participant(1, "Bob", "Smith"); originalList.Add(expectedParticipant); IRepository <Participant> store = new InMemoryParticipantStore(originalList); var result = store.Single(p => p.ID == expectedParticipant.ID); //Assert Results Assert.That(result, Is.EqualTo(expectedParticipant)); }
public void InMemoryParticipantStore_canUpsertManyAndThenSelect() { var participant1 = new Participant(null, "Bob", "Smith"); var participant2 = new Participant(null, "John", "Doe"); var participantArray = new Participant[] { participant1, participant2 }; IRepository <Participant> store = new InMemoryParticipantStore(); store.Add(participantArray); var resultParticipant = store.Single(a => a.FirstName == participant1.FirstName); Assert.That(resultParticipant.FirstName, Is.EqualTo(participant1.FirstName)); Assert.That(resultParticipant.ID, Is.Not.Null); }
public void InMemoryParticipantStore_ReturnsNullWhenNotFound() { //Setup List <Participant> originalList = new List <Participant>(); var participant = new Participant(1, "Bob", "Smith"); originalList.Add(participant); var nonExistantID = 12345; IRepository <Participant> store = new InMemoryParticipantStore(originalList); var result = store.Single(p => p.ID == nonExistantID); //Assert Results Assert.That(result, Is.Null); }
public void Startup_RegistersInMemoryDataStore() { //Arrange and Act - Startup's methods get exercised on the line below by the test mvc builder. var factory = new WebApplicationFactory <Startup>(); //Fetch the service that I want to make sure is in there. Participant is a table/object I am persisting. var resultRepository = factory.Services.GetService(typeof(IRepository <Participant>)); //Assert try { InMemoryParticipantStore repository = (InMemoryParticipantStore)resultRepository; // Pretty sure there is a better way to do this. } catch (Exception ex) { Assert.Fail("Unexpected repository type registered: {}", ex.Message); } }
public void InMemoryParticipantStore_canDispose() { //Arrange var participant1 = new Participant(null, "Bob", "Smith"); var participant2 = new Participant(null, "John", "Doe"); var participantArray = new Participant[] { participant1, participant2 }; IRepository <Participant> store = new InMemoryParticipantStore(); participantArray = store.Add(participantArray).ToArray(); //Act store.Dispose(); //Assert var remainingParticipants = store.All(); Assert.That(remainingParticipants.Count(), Is.EqualTo(0)); }
public void InMemoryParticipantStore_CanDelete() { //Setup List <Participant> originalList = new List <Participant>(); var participantToDelete = new Participant(1, "Bob", "Smith"); var secondParticipant = new Participant(2, "Joe", "Doe"); originalList.Add(participantToDelete); originalList.Add(secondParticipant); IRepository <Participant> store = new InMemoryParticipantStore(originalList); store.Delete(p => p.ID == participantToDelete.ID); var resultList = store.All().ToList(); var remainingParticipant = resultList.SingleOrDefault(p => p.ID == secondParticipant.ID); //Assert Results Assert.That(resultList.Count, Is.EqualTo(1)); Assert.That(remainingParticipant, Is.Not.Null); }
public void InMemoryParticipantStore_DefaultConstructs() { IRepository <Participant> dummystorage = new InMemoryParticipantStore(); }