Beispiel #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);
        }
Beispiel #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);
        }
Beispiel #3
0
        public void DateNotInPast_DecoratedSaverNullReference_NegativeTest()
        {
            ////Arrange
            ISave <Event> testSaver;

            ////Act
            void TestAction()
            {
                testSaver = new DateNotInPastSaver <Event>(null, "Date");
            }

            ////Assert
            Assert.Throws <ArgumentNullException>(TestAction);
        }
Beispiel #4
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);
        }
        /// <summary>
        /// Create concrete saver.
        /// </summary>
        /// <returns>Concrete saver.</returns>
        public ISave <T> CreateSaver()
        {
            switch (typeof(T).Name)
            {
            case "Venue":
                return(new SqlUniqueSeparateSaver <T>(   ////venue unique by Description field
                           new SqlSaver <T>(_connectionString),
                           _connectionString,
                           new[] { "Description" }));

            case "Layout":
                return(new SqlUniqueSeparateSaver <T>(
                           new SqlSaver <T>(_connectionString),
                           _connectionString,
                           new[] { "Description" }, ////layout unique by Description field
                           "VenueId"));             ////in its venue

            case "Area":
                return(new SqlUniqueSeparateSaver <T>(
                           new SqlSaver <T>(_connectionString),
                           _connectionString,
                           new[] { "Description" }, ////unique by Description field
                           "LayoutId"));            ////in layout

            case "Seat":
                return(new SqlUniqueTogetherSaver <T>(
                           new SqlSaver <T>(_connectionString),
                           _connectionString,
                           new[] { "Row", "Number" }, ////seat unique by Row or Number field
                           "AreaId"));                ////in its area

            case "Event":
                ISave <T> saver;

                saver = new SqlProcedureSaver <T>(_connectionString); ////Simple event saver

                saver = new SqlUniqueSeparateSaver <T>(               ////Decorated with validation for unique date in layout
                    saver,
                    _connectionString,
                    new[] { "Date" },
                    "LayoutId");

                saver = new SqlCheckForSeatSaver <T>(    ////Decorated with validation for existing seat
                    saver,
                    _connectionString);

                saver = new DateNotInPastSaver <T>(    ////Decorated with validation for date not in past
                    saver,
                    "Date");

                return(saver);

            case "EventArea":
                return(new SqlSaver <T>(_connectionString));

            case "EventSeat":
                return(new SqlSaver <T>(_connectionString));

            case "PurchaseHistory":
                return(new SqlSaver <T>(_connectionString));

            default:
                return(null);
            }
        }