コード例 #1
0
        public void CreateDTOFromEntity_NullInput()
        {
            //Act
            var revisionDTO = RevisionDTO.CreateDTOFromEntity(entity: null);

            //Assert
            Assert.NotNull(revisionDTO);
        }
コード例 #2
0
        public void IsSame_BothEmpty_ExpectTrue()
        {
            //Arrange
            var revisionDTO = new RevisionDTO();

            //Act
            var testResult = revisionDTO.IsSame(new RevisionDTO());

            //Assert
            Assert.True(testResult);
        }
コード例 #3
0
        public void IsEmpty_AllPropertiesEmpty_ExpectTrue()
        {
            //Arrange
            var revisionDTO = new RevisionDTO();

            //Act
            var testResult = revisionDTO.IsEmpty();

            //Assert
            Assert.True(testResult);
        }
コード例 #4
0
        public void IsSame_NullInput_ExpectFalse()
        {
            //Arrange
            var revisionDTO = new RevisionDTO();

            //Act
            var testResult = revisionDTO.IsSame(null);

            //Assert
            Assert.False(testResult);
        }
コード例 #5
0
        public void IsEmpty_AllPropertiesNonEmpty_ExpectFalse()
        {
            //Arrange
            var entity      = new RevisionBuilder(null).Default().Build();
            var revisionDTO = RevisionDTO.CreateDTOFromEntity(entity);

            //Act
            var testResult = revisionDTO.IsEmpty();

            //Assert
            Assert.False(testResult);
        }
コード例 #6
0
        public void IsSame_AllPropertiesSame_ExpectTrue()
        {
            //Arrange
            var entity       = new RevisionBuilder(null).Default().Build();
            var revisionDTO1 = RevisionDTO.CreateDTOFromEntity(entity);
            var revisionDTO2 = RevisionDTO.CreateDTOFromEntity(entity);

            //Act
            var testResult = revisionDTO1.IsSame(revisionDTO2);

            //Assert
            Assert.True(testResult);
        }
コード例 #7
0
        public void IsSame_AllPropertiesDifferent_ExpectFalse()
        {
            //Arrange
            var entity1      = new RevisionBuilder(null).Default().Build();
            var revisionDTO1 = RevisionDTO.CreateDTOFromEntity(entity1);
            var entity2      = new RevisionBuilder(null).Random().Build();
            var revisionDTO2 = RevisionDTO.CreateDTOFromEntity(entity2);

            //Act
            var testResult = revisionDTO1.IsSame(revisionDTO2);

            //Assert
            Assert.False(testResult);
        }
コード例 #8
0
        public void ToEntity_EmptyProperties()
        {
            //Arrange
            var revisionnDTO = new RevisionDTO();

            //Act
            var entity = revisionnDTO.ToEntity();

            //Assert
            Assert.NotNull(entity);
            Assert.Equal(revisionnDTO.Id, entity.Id);
            Assert.Equal(revisionnDTO.Title, entity.Title);
            Assert.Equal(revisionnDTO.Body, entity.Body);
        }
コード例 #9
0
        public bool IsSame(RevisionDTO otherRevision)
        {
            if (otherRevision == null)
            {
                return(false);
            }

            if (Title != otherRevision.Title || Body != otherRevision.Body)
            {
                return(false);
            }

            return(true);
        }
コード例 #10
0
        public void IsEmpty_MixProperties_ExpectFalse()
        {
            //Arrange
            var revisionDTO = new RevisionDTO()
            {
                Body             = "test body",
                CreatedDateLocal = DateTime.Now.ToString("yyyy-MM-dd")
            };

            //Act
            var testResult = revisionDTO.IsEmpty();

            //Assert
            Assert.False(testResult);
        }
コード例 #11
0
        public void IsSame_MixProperties_ExpectFalse()
        {
            //Arrange
            var entity       = new RevisionBuilder(null).Default().Build();
            var revisionDTO1 = RevisionDTO.CreateDTOFromEntity(entity);

            entity.Title = "IsSame_MixProperties_ExpectFalse";
            var revisionDTO2 = RevisionDTO.CreateDTOFromEntity(entity);

            //Act
            var testResult = revisionDTO1.IsSame(revisionDTO2);

            //Assert
            Assert.False(testResult);
        }
コード例 #12
0
        public void Constructor_InputSingleItemList_ExpectCorrectCountAndLatest()
        {
            //Arrange
            var size       = 1;
            var entityList = new RevisionBuilder(null).Default().BuildCollection(size);

            //Act
            var testResult = new RevisionList(entityList);

            //Assert
            var expectResult = RevisionDTO.CreateDTOFromEntity(entityList.Last(), index: size);

            Assert.Equal(size, testResult.Count);
            Assert.True(expectResult.IsSame(testResult.Latest));
            Assert.Equal(size, testResult.Latest.Index);
        }
コード例 #13
0
        public static RevisionDTO CreateDTOFromEntity(PoemRevision entity, int index = 0)
        {
            var revisionDTO = new RevisionDTO();

            if (entity != null)
            {
                revisionDTO.Id               = entity.Id;
                revisionDTO.Title            = entity.Title;
                revisionDTO.Body             = entity.Body;
                revisionDTO.CreatedDateLocal = entity.CreatedDateUTC.ToLocalTime().ToString("yyyy-MM-dd");
                revisionDTO.DisplayName      = index.ToString() + " [" + revisionDTO.CreatedDateLocal + "]";
            }
            ;
            revisionDTO.Index = index;

            return(revisionDTO);
        }
コード例 #14
0
        public void CreateDTOFromEntity_ValidInput()
        {
            //Arrange
            var revisionEntity = new RevisionBuilder(null).Default().Build();

            //Act
            var index       = 1;
            var revisionDTO = RevisionDTO.CreateDTOFromEntity(revisionEntity, index);

            //Assert
            Assert.NotNull(revisionDTO);
            Assert.Equal(revisionEntity.Id, revisionDTO.Id);
            Assert.Equal(revisionEntity.Title, revisionDTO.Title);
            Assert.Equal(revisionEntity.Body, revisionDTO.Body);
            Assert.Equal(revisionEntity.CreatedDateUTC.ToLocalTime().ToString("yyyy-MM-dd"),
                         revisionDTO.CreatedDateLocal);
            Assert.Equal(index, revisionDTO.Index);
        }
コード例 #15
0
        public void ToEntity_NonEmptyProperties()
        {
            //Arrange
            var expectResult = new RevisionBuilder(null).Default().Build();
            var revisionnDTO = new RevisionDTO()
            {
                Id    = expectResult.Id,
                Title = expectResult.Title,
                Body  = expectResult.Body
            };

            //Act
            var testResult = revisionnDTO.ToEntity();

            //Assert
            Assert.NotNull(testResult);
            Assert.Equal(expectResult.Id, testResult.Id);
            Assert.Equal(expectResult.Title, testResult.Title);
            Assert.Equal(expectResult.Body, testResult.Body);
        }
コード例 #16
0
        public void GetEnumerator_InputSingleItemList_ExpectOneItemInLoop()
        {
            //Arrange
            var size       = 1;
            var entityList = new RevisionBuilder(null).Default().BuildCollection(size);

            //Act
            var testResult = new RevisionList(entityList);

            //Assert
            var expectResult = RevisionDTO.CreateDTOFromEntity(entityList.Last());
            var count        = 1;

            foreach (var item in testResult)
            {
                Assert.False(count > size);
                Assert.True(expectResult.IsSame(item));
                Assert.Equal(count, item.Index);
                count++;
            }
        }
コード例 #17
0
        public void GetEnumerator_InputMultipleItemsList_ExpectCorrectItemsInLoop()
        {
            //Arrange
            var size       = 3;
            var entityList = new RevisionBuilder(null).Default().BuildCollection(size);

            //Act
            var testResult = new RevisionList(entityList);

            //Assert
            var expectList = entityList
                             .OrderBy(e => e.CreatedDateUTC)
                             .Select(e => RevisionDTO.CreateDTOFromEntity(e));
            var count = 1;

            foreach (var item in testResult)
            {
                Assert.False(count > size);
                Assert.True(expectList.ElementAt(count - 1).IsSame(item));
                Assert.Equal(count, item.Index);
                count++;
            }
        }