コード例 #1
0
        public void SecondAddedDataMustReturnId2()
        {
            MockRepository rep   = new MockRepository();
            MockClass      data1 = new MockClass();
            MockClass      data2 = new MockClass();

            // When
            long resp1 = (long)rep.Add(data1);
            long resp2 = (long)rep.Add(data2);

            // Then
            Assert.AreEqual(resp1, 1, "First added data must have ID 1");
            Assert.AreEqual(resp2, 2, "First added data must have ID 2");
        }
コード例 #2
0
        public void GetAllMustGetAllAddedItems()
        {
            // Given
            MockRepository rep   = new MockRepository();
            MockClass      data1 = new MockClass();
            MockClass      data2 = new MockClass();
            MockClass      data3 = new MockClass();

            // When
            rep.Add(data1);
            rep.Add(data2);
            rep.Add(data3);
            List <MockClass> resp = rep.GetAll().ToList();

            // Then
            Assert.AreEqual(resp.Count, 3, "Returned list must have same number of added objects");
        }
コード例 #3
0
        public void GetAllMustReturnClonedObjects()
        {
            // Given
            MockRepository rep   = new MockRepository();
            MockClass      data1 = new MockClass();
            MockClass      data2 = new MockClass();
            MockClass      data3 = new MockClass();

            // When
            rep.Add(data1);
            rep.Add(data2);
            rep.Add(data3);
            List <MockClass> resp = rep.GetAll().ToList();

            // Then
            Assert.IsFalse(resp.Contains(data1), "Returned list must not contain the original objects");
            Assert.IsFalse(resp.Contains(data2), "Returned list must not contain the original objects");
            Assert.IsFalse(resp.Contains(data3), "Returned list must not contain the original objects");
        }
コード例 #4
0
        public void FirstAddedDataMustReturnId1()
        {
            MockRepository rep  = new MockRepository();
            MockClass      data = new MockClass();

            // When
            long resp = (long)rep.Add(data);

            // Then
            Assert.AreEqual(resp, 1, "First added data must have ID 1");
        }
コード例 #5
0
        public void AddDataWithIdMustRaiseException()
        {
            // Given
            MockRepository rep  = new MockRepository();
            MockClass      data = new MockClass();

            data.Id = 1;

            // When / Then
            ArgumentException exc = Assert.Throws <ArgumentException>(() => rep.Add(data), "Adding data with Id must raise exception");
        }
コード例 #6
0
        public void adds_new_entity()
        {
            var mockRepository = new MockRepository(new List <MockEntity>());

            Assert.False(mockRepository.Exists(1));

            mockRepository.Add(new MockEntity {
                Id = 1
            });

            Assert.True(mockRepository.Exists(1));
        }
コード例 #7
0
        public void errors_when_adding_entity_with_existing_key()
        {
            var entities = new List <MockEntity> {
                new MockEntity {
                    Id = 1
                }
            };
            var mockRepository = new MockRepository(entities);

            Assert.Throws <ArgumentException>(() => mockRepository.Add(new MockEntity {
                Id = 1
            }));
        }
コード例 #8
0
        public void increments_entity_id_when_new_entity_is_added()
        {
            var entities = new List <MockEntity> {
                new MockEntity {
                    Id = 8
                }
            };
            var newEntity      = new MockEntity();
            var mockRepository = new MockRepository(entities);

            mockRepository.Add(newEntity);

            Assert.Equal(9, newEntity.Id);
            Assert.True(mockRepository.Exists(9));
        }
コード例 #9
0
        public void DeletingAnElementMustRaiseAnExceptionIdTryingToDeleteAgain()
        {
            // Given
            MockRepository rep  = new MockRepository();
            MockClass      data = new MockClass();
            long           resp = (long)rep.Add(data);

            // When
            rep.Delete(resp);

            //Then
            NotExistingValueException exc = Assert.Throws <NotExistingValueException>(() => rep.Delete(resp), "Deleting already deleted data must raise exception");

            Assert.AreEqual(exc.ErrorCode, ErrorCode.VALUE_NOT_EXISTING_IN_DATABASE, "Raised exception code must be VALUE_NOT_EXISTING_IN_DATABASE");
        }
コード例 #10
0
        public void GetElementMustBeDifferentAsOriginal()
        {
            // Given
            MockRepository rep        = new MockRepository();
            MockClass      data1      = new MockClass();
            string         objectData = "ObjectData";

            data1.Data = objectData;

            // When
            long      resp1 = (long)rep.Add(data1);
            MockClass resp  = rep.Get(resp1);

            // Then
            Assert.AreNotEqual(resp, data1, "Returned object must be different from original one");
        }
コード例 #11
0
        public void GetElementMustReturnSameData()
        {
            // Given
            MockRepository rep        = new MockRepository();
            MockClass      data1      = new MockClass();
            string         objectData = "ObjectData";

            data1.Data = objectData;

            // When
            long      resp1 = (long)rep.Add(data1);
            MockClass resp  = rep.Get(resp1);

            // Then
            Assert.AreEqual(resp.Data, objectData, "Returned object must have same data as added one");
        }
コード例 #12
0
        public void UpdatingAnInexistentElementMustRaiseAnException()
        {
            // Given
            MockRepository rep  = new MockRepository();
            MockClass      data = new MockClass();

            // When
            long resp = (long)rep.Add(data);

            MockClass updatedData = new MockClass();

            updatedData.Id = resp + 1;

            // When / Then
            KeyNotFoundException exc = Assert.Throws <KeyNotFoundException>(() => rep.Update(updatedData), "Updating inexistent data must raise exception");
        }
コード例 #13
0
        public void UpdatingDataMustChangeDataInSet()
        {
            // Given
            MockRepository rep  = new MockRepository();
            MockClass      obj  = new MockClass();
            string         data = "Data";

            // When
            long resp = (long)rep.Add(obj);

            MockClass addedData = rep.Get(resp);

            addedData.Data = data;

            rep.Update(addedData);

            // Then
            Assert.AreEqual(rep.Get(resp).Data, data, "Object's data must be same as updated one");
        }
コード例 #14
0
        public void AddNullDataMustRaiseException()
        {
            // Given
            MockRepository rep = new MockRepository();

            // When / Then
            NotValidValueException exc = Assert.Throws <NotValidValueException>(() => rep.Add(null), "Adding null object must raise exception");

            Assert.AreEqual(exc.ErrorCode, ErrorCode.NULL_VALUE_NOT_ALLOWED);
        }