public async Task Given_AValidDateRangeEffectiveContractObjectId_When_GetIsInvoked_Then_TheDateRangeEffectiveContractObjectShouldBeReturned()
        {
            var dateRangeEffectiveDtoObject = new DateRangeEffectiveDtoObject
            {
                CreatedByUserId    = StaticTestValues.CreatedByUserId1,
                CreatedOn          = StaticTestValues.CreatedOnDateTimeOffset1,
                EffectiveEndDate   = StaticTestValues.EffectiveEndDateTimeOffset1,
                EffectiveStartDate = StaticTestValues.EffectiveStartDateTimeOffset1,
                Id = StaticTestValues.ValidId1,
                LastUpdatedByUserId = StaticTestValues.LastUpdatedByUserId1,
                LastUpdatedOn       = StaticTestValues.LastUpdatedOnDateTimeOffset1,
                Property            = StaticTestValues.ValidProperty1,
                VirtualProperty     = StaticTestValues.ValidVirtualProperty1
            };

            MockDateRangeEffectiveObjectsDal.Setup(m => m.Read(StaticTestValues.ValidId1)).ReturnsAsync(dateRangeEffectiveDtoObject);

            var response = await(await DateRangeEffectiveContractObjectsController.Get(1)).ExecuteAsync(CancellationToken.None);
            var country  = JsonConvert.DeserializeObject <DateRangeEffectiveContractObject>(await response.Content.ReadAsStringAsync());

            Assert.AreEqual(StaticTestValues.CreatedByUserId1, country.CreatedByUserId);
            Assert.AreEqual(StaticTestValues.CreatedOnDateTimeOffset1, country.CreatedOn);
            Assert.AreEqual(StaticTestValues.EffectiveEndDateTimeOffset1, country.EffectiveEndDate);
            Assert.AreEqual(StaticTestValues.EffectiveStartDateTimeOffset1, country.EffectiveStartDate);
            Assert.AreEqual(StaticTestValues.ValidId1, country.Id);
            Assert.AreEqual(StaticTestValues.LastUpdatedByUserId1, country.LastUpdatedByUserId);
            Assert.AreEqual(StaticTestValues.LastUpdatedOnDateTimeOffset1, country.LastUpdatedOn);
            Assert.AreEqual(StaticTestValues.ValidProperty1, country.Property);
            Assert.AreEqual(StaticTestValues.ValidVirtualProperty1, country.VirtualProperty);
        }
        public async Task Given_AValidDateRangeEffectiveContractObject_When_PutIsInvoked_Then_TheDateRangeEffectiveContractObjectShouldBeReturned()
        {
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new string[0]);
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Update(It.IsAny <DateRangeEffectiveDtoObject>())).ReturnsAsync(new DateRangeEffectiveDtoObject
            {
                CreatedByUserId    = StaticTestValues.CreatedByUserId1,
                CreatedOn          = StaticTestValues.CreatedOnDateTimeOffset1,
                EffectiveEndDate   = StaticTestValues.EffectiveEndDateTimeOffset1,
                EffectiveStartDate = StaticTestValues.EffectiveStartDateTimeOffset1,
                Id = StaticTestValues.ValidId1,
                LastUpdatedByUserId = StaticTestValues.LastUpdatedByUserId1,
                LastUpdatedOn       = StaticTestValues.LastUpdatedOnDateTimeOffset1,
                Property            = StaticTestValues.ValidProperty1,
                VirtualProperty     = StaticTestValues.ValidVirtualProperty1
            });

            var response = await(await DateRangeEffectiveContractObjectsController.Put(new DateRangeEffectiveContractObject())).ExecuteAsync(CancellationToken.None);
            var dateRangeEffectiveContractObject = JsonConvert.DeserializeObject <DateRangeEffectiveContractObject>(await response.Content.ReadAsStringAsync());

            Assert.AreEqual(StaticTestValues.CreatedByUserId1, dateRangeEffectiveContractObject.CreatedByUserId);
            Assert.AreEqual(StaticTestValues.CreatedOnDateTimeOffset1, dateRangeEffectiveContractObject.CreatedOn);
            Assert.AreEqual(StaticTestValues.EffectiveEndDateTimeOffset1, dateRangeEffectiveContractObject.EffectiveEndDate);
            Assert.AreEqual(StaticTestValues.EffectiveStartDateTimeOffset1, dateRangeEffectiveContractObject.EffectiveStartDate);
            Assert.AreEqual(StaticTestValues.ValidId1, dateRangeEffectiveContractObject.Id);
            Assert.AreEqual(StaticTestValues.LastUpdatedByUserId1, dateRangeEffectiveContractObject.LastUpdatedByUserId);
            Assert.AreEqual(StaticTestValues.LastUpdatedOnDateTimeOffset1, dateRangeEffectiveContractObject.LastUpdatedOn);
            Assert.AreEqual(StaticTestValues.ValidProperty1, dateRangeEffectiveContractObject.Property);
            Assert.AreEqual(StaticTestValues.ValidVirtualProperty1, dateRangeEffectiveContractObject.VirtualProperty);
        }
        public async Task Given_AValidDateRangeEffectiveContractObjectId_When_GetIsInvoked_Then_OkStatusCodeShouldBeReturned()
        {
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Read(1)).ReturnsAsync(new DateRangeEffectiveDtoObject());

            var response = await(await DateRangeEffectiveContractObjectsController.Get(1)).ExecuteAsync(CancellationToken.None);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
        public async Task Given_AnyDateRangeEffectiveContractObjectId_When_HardDeleteIsInvoked_Then_DalDeleteMethodShouldOnlyBeInvokedOnce()
        {
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Delete(It.IsAny <int>())).Throws(new ObjectNotFoundException());

            await(await DateRangeEffectiveContractObjectsController.HardDelete(StaticTestValues.InvalidId1)).ExecuteAsync(CancellationToken.None);

            MockDateRangeEffectiveObjectsDal.Verify(m => m.Delete(It.IsAny <int>()), Times.Once);
        }
        public async Task Given_AnInvalidDateRangeEffectiveContractObjectId_When_HardDeleteIsInvoked_Then_NotFoundStatusCodeShouldBeReturned()
        {
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Delete(StaticTestValues.InvalidId1)).Throws(new ObjectNotFoundException());

            var response = await(await DateRangeEffectiveContractObjectsController.HardDelete(StaticTestValues.InvalidId1)).ExecuteAsync(CancellationToken.None);

            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
        public async Task Given_AValidDateRangeEffectiveContractObjectId_When_HardDeleteIsInvoked_Then_NoContentStatusCodeShouldBeReturned()
        {
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Delete(StaticTestValues.ValidId1)).Returns(Task.Factory.StartNew(() => { }));

            var response = await(await DateRangeEffectiveContractObjectsController.HardDelete(StaticTestValues.ValidId1)).ExecuteAsync(CancellationToken.None);

            Assert.AreEqual(HttpStatusCode.NoContent, response.StatusCode);
        }
        public async Task Given_AValidDateRangeEffectiveContractObjectId_When_DeleteIsInvoked_Then_DalUpdateMethodShouldOnlyBeInvokedOnce()
        {
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Read(StaticTestValues.ValidId1)).ReturnsAsync(new DateRangeEffectiveDtoObject());

            await(await DateRangeEffectiveContractObjectsController.Delete(StaticTestValues.ValidId1)).ExecuteAsync(CancellationToken.None);

            MockDateRangeEffectiveObjectsDal.Verify(m => m.Update(It.IsAny <DateRangeEffectiveDtoObject>()), Times.Once);
        }
        public async Task Given_AnInvalidDateRangeEffectiveContractObjectId_When_DeleteIsInvoked_Then_DalUpdateMethodShouldNotBeInvoked()
        {
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Read(0)).ThrowsAsync(new ObjectNotFoundException());

            await(await DateRangeEffectiveContractObjectsController.Delete(0)).ExecuteAsync(CancellationToken.None);

            MockDateRangeEffectiveObjectsDal.Verify(m => m.Update(It.IsAny <DateRangeEffectiveDtoObject>()), Times.Never);
        }
        public async Task Given_AnyDateRangeEffectiveContractObjectId_When_GetIsInvoked_Then_DalReadMethodShouldOnlyBeInvokedOnce()
        {
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Read(0)).ThrowsAsync(new ObjectNotFoundException());

            await(await DateRangeEffectiveContractObjectsController.Get(0)).ExecuteAsync(CancellationToken.None);

            MockDateRangeEffectiveObjectsDal.Verify(m => m.Read(It.IsAny <int>()), Times.Once);
        }
        public async Task Given_AValidDateRangeEffectiveContractObjectId_When_DeleteIsInvoked_Then_DalUpdateMethodShouldBeInvokedWithUpdatedAuditInformation()
        {
            MockUser.SetupGet(m => m.Id).Returns(StaticTestValues.LastUpdatedByUserId2.Value);
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Read(StaticTestValues.ValidId1)).ReturnsAsync(new DateRangeEffectiveDtoObject());

            await(await DateRangeEffectiveContractObjectsController.Delete(StaticTestValues.ValidId1)).ExecuteAsync(CancellationToken.None);

            MockDateRangeEffectiveObjectsDal.Verify(m => m.Update(It.Is <DateRangeEffectiveDtoObject>(c => c.LastUpdatedByUserId == StaticTestValues.LastUpdatedByUserId2 && c.LastUpdatedOn > DateTimeOffset.UtcNow.AddSeconds(-1) && c.LastUpdatedOn <DateTimeOffset.UtcNow.AddSeconds(1) && c.EffectiveEndDate> DateTimeOffset.UtcNow.AddSeconds(-1) && c.EffectiveEndDate < DateTimeOffset.UtcNow.AddSeconds(1))));
        }
        public async Task Given_AValidDateRangeEffectiveContractObject_When_PutIsInvoked_Then_DalUpdateMethodShouldOnlyBeInvokedOnce()
        {
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new string[0]);
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Update(It.IsAny <DateRangeEffectiveDtoObject>())).ReturnsAsync(new DateRangeEffectiveDtoObject());

            await(await DateRangeEffectiveContractObjectsController.Put(new DateRangeEffectiveContractObject())).ExecuteAsync(CancellationToken.None);

            MockDateRangeEffectiveObjectsDal.Verify(m => m.Update(It.IsAny <DateRangeEffectiveDtoObject>()), Times.Once);
        }
        public async Task Given_AValidDateRangeEffectiveContractObject_When_PutIsInvoked_Then_OkResponseShouldBeReturned()
        {
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new string[0]);
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Update(It.IsAny <DateRangeEffectiveDtoObject>())).ReturnsAsync(new DateRangeEffectiveDtoObject());

            var response = await(await DateRangeEffectiveContractObjectsController.Put(new DateRangeEffectiveContractObject())).ExecuteAsync(CancellationToken.None);

            Assert.AreEqual(HttpStatusCode.OK, response.StatusCode);
        }
        public async Task Given_AnInvalidDateRangeEffectiveContractObject_When_PutIsInvoked_Then_ValidateContractMethodShouldOnlyBeInvokedOnce()
        {
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new[] { StaticTestValues.ContractValidatorErrorMessage1 });
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Update(It.IsAny <DateRangeEffectiveDtoObject>())).ReturnsAsync(new DateRangeEffectiveDtoObject());

            await(await DateRangeEffectiveContractObjectsController.Put(new DateRangeEffectiveContractObject())).ExecuteAsync(CancellationToken.None);

            MockContractValidator.Verify(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>()), Times.Once);
        }
        public async Task Given_AValidDateRangeEffectiveContractObject_When_PostIsInvoked_Then_DalCreateMethodShouldBeInvokedWithUpdatedAuditInformation()
        {
            MockUser.SetupGet(m => m.Id).Returns(StaticTestValues.CreatedByUserId2);
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new string[0]);
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Create(It.IsAny <DateRangeEffectiveDtoObject>())).ReturnsAsync(new DateRangeEffectiveDtoObject());

            await(await DateRangeEffectiveContractObjectsController.Post(new DateRangeEffectiveContractObject())).ExecuteAsync(CancellationToken.None);

            MockDateRangeEffectiveObjectsDal.Verify(m => m.Create(It.Is <DateRangeEffectiveDtoObject>(c => c.LastUpdatedByUserId == null && c.LastUpdatedOn == null && c.CreatedByUserId == StaticTestValues.CreatedByUserId2 && c.CreatedOn > DateTimeOffset.UtcNow.AddSeconds(-1) && c.CreatedOn < DateTimeOffset.UtcNow.AddSeconds(1))));
        }
        public async Task Given_ADateRangeEffectiveContractObjectWithAnInvalidId_When_PutIsInvoked_Then_NotFoundStatusShouldBeReturned()
        {
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new string[0]);
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Update(It.Is <DateRangeEffectiveDtoObject>(c => c.Id == StaticTestValues.InvalidId1))).ThrowsAsync(new ObjectNotFoundException());

            var response = await(await DateRangeEffectiveContractObjectsController.Put(new DateRangeEffectiveContractObject {
                Id = StaticTestValues.InvalidId1
            })).ExecuteAsync(CancellationToken.None);

            Assert.AreEqual(HttpStatusCode.NotFound, response.StatusCode);
        }
        public async Task Given_AValidDateRangeEffectiveContractObject_When_PostIsInvoked_Then_ResponseShouldContainTheUrlToGetTheCreatedContract()
        {
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new string[0]);
            MockDateRangeEffectiveObjectsDal.Setup(m => m.Create(It.IsAny <DateRangeEffectiveDtoObject>())).ReturnsAsync(new DateRangeEffectiveDtoObject {
                Id = StaticTestValues.ValidId1
            });

            var response = await(await DateRangeEffectiveContractObjectsController.Post(new DateRangeEffectiveContractObject())).ExecuteAsync(CancellationToken.None);

            Assert.AreEqual($"http://localhost/v1/{StaticTestValues.ControllerName}/{StaticTestValues.ValidId1}?controller={StaticTestValues.ControllerName}", response.Headers.Location.ToString());
        }