Пример #1
0
        public void DateNotInPast_WhenDateFieldNotExist_SouldThrowException()
        {
            ////Arrange
            var testEntity = new Event
            {
                Id          = 1,
                Date        = DateTime.Now.Date.AddDays(1).AddHours(15),
                Description = "EventDescription1",
                LayoutId    = 1,
                Name        = "EventName1",
            };
            var saverMock = new Mock <ISave <Event> >();

            saverMock.Setup(s => s.Save(testEntity)).Returns(testEntity);

            var testSaver = new DateNotInPastSaver <Event>(saverMock.Object, "BadField");

            ////Act
            void TestAction()
            {
                testSaver.Save(testEntity);
            }

            ////Assert
            Assert.Throws <MissingFieldException>(TestAction);
        }
Пример #2
0
        public void DateNotInPast_FieldExistButNotDateType_NegativeTest()
        {
            ////Arrange
            var testEntity = new Event
            {
                Id          = 1,
                Date        = DateTime.Now.Date.AddDays(1).AddHours(15),
                Description = "EventDescription1",
                LayoutId    = 1,
                Name        = "EventName1",
            };
            var saverMock = new Mock <ISave <Event> >();

            saverMock.Setup(s => s.Save(testEntity)).Returns(testEntity);

            var testSaver = new DateNotInPastSaver <Event>(saverMock.Object, "Name");

            ////Act
            void TestAction()
            {
                testSaver.Save(testEntity);
            }

            ////Assert
            Assert.Throws <InvalidCastException>(TestAction);
        }
Пример #3
0
        public void DateNotInPast_PositiveTest()
        {
            ////Arrange
            var testEntity = new Event
            {
                Id          = 1,
                Date        = DateTime.Now.Date.AddDays(1).AddHours(15),
                Description = "EventDescription1",
                LayoutId    = 1,
                Name        = "EventName1",
            };

            var saverMock = new Mock <ISave <Event> >();

            saverMock.Setup(s => s.Save(testEntity)).Returns(testEntity);

            var testSaver = new DateNotInPastSaver <Event>(saverMock.Object, "Date");

            ////Act
            var testResult = testSaver.Save(testEntity);

            ////Assert
            testEntity.Should().BeEquivalentTo(testResult);
        }