public void InMemoryParticipantStore_canUpsert()
        {
            var participantAdded            = new Participant(1, "Bob", "Smith");
            IRepository <Participant> store = new InMemoryParticipantStore();

            store.Add(participantAdded);

            var updatedParticipant = new Participant(1, "Joe", "Smith");

            store.Add(updatedParticipant);

            var resultParticipant = store.Single(a => a.ID == participantAdded.ID);

            Assert.That(resultParticipant, Is.EqualTo(updatedParticipant));
        }
        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 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));
        }
Exemplo n.º 4
0
        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_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_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));
        }