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_AnInvalidDateRangeEffectiveContractObject_When_PutIsInvoked_Then_DalUpdateMethodShouldNotBeInvoked()
        {
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new[] { StaticTestValues.ContractValidatorErrorMessage1 });

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

            MockDateRangeEffectiveObjectsDal.Verify(m => m.Update(It.IsAny <DateRangeEffectiveDtoObject>()), Times.Never);
        }
        public async Task Given_AnInvalidDateRangeEffectiveContractObject_When_PutIsInvoked_Then_BadRequestStatusCodeShouldBeReturned()
        {
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new[] { StaticTestValues.ContractValidatorErrorMessage1 });

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

            Assert.AreEqual(HttpStatusCode.BadRequest, response.StatusCode);
        }
        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_TheErrorMessagesShouldBeReturned()
        {
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new[] { StaticTestValues.ContractValidatorErrorMessage1, StaticTestValues.ContractValidatorErrorMessage2 });

            var     response        = await(await DateRangeEffectiveContractObjectsController.Put(new DateRangeEffectiveContractObject())).ExecuteAsync(CancellationToken.None);
            dynamic responseContent = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());

            Assert.AreEqual($"{StaticTestValues.ContractValidatorErrorMessage1}\n{StaticTestValues.ContractValidatorErrorMessage2}", responseContent.Message.ToString());
        }
        public async Task Given_AValidDateRangeEffectiveContractObject_When_PutIsInvoked_Then_DalUpdateMethodShouldBeInvokedWithUpdatedAuditInformation()
        {
            MockUser.SetupGet(m => m.Id).Returns(StaticTestValues.LastUpdatedByUserId2.Value);
            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.Is <DateRangeEffectiveDtoObject>(c => c.LastUpdatedByUserId == StaticTestValues.LastUpdatedByUserId2 && c.LastUpdatedOn > DateTimeOffset.UtcNow.AddSeconds(-1) && c.LastUpdatedOn < DateTimeOffset.UtcNow.AddSeconds(1))));
        }
        public async Task Given_ADateRangeEffectiveContractObjectWithAnInvalidEffectiveDateRange_When_PutIsInvoked_Then_DalUpdateMethodShouldNotBeInvoked()
        {
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new string[0]);

            await(await DateRangeEffectiveContractObjectsController.Put(new DateRangeEffectiveContractObject {
                EffectiveStartDate = DateTimeOffset.MaxValue, EffectiveEndDate = DateTimeOffset.MinValue
            })).ExecuteAsync(CancellationToken.None);

            MockDateRangeEffectiveObjectsDal.Verify(m => m.Update(It.IsAny <DateRangeEffectiveDtoObject>()), Times.Never);
        }
        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_ADateRangeEffectiveContractObjectWithAnInvalidEffectiveDateRange_When_PutIsInvoked_Then_TheReasonShouldBeReturned()
        {
            MockContractValidator.Setup(m => m.ValidateContract(It.IsAny <DateRangeEffectiveContractObject>())).ReturnsAsync(new string[0]);

            var response = await(await DateRangeEffectiveContractObjectsController.Put(new DateRangeEffectiveContractObject {
                EffectiveStartDate = DateTimeOffset.MaxValue, EffectiveEndDate = DateTimeOffset.MinValue
            })).ExecuteAsync(CancellationToken.None);
            dynamic responseContent = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());

            Assert.AreEqual(ErrorMessages.InvalidEffectiveDateRange, responseContent.Message.ToString());
        }
        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());
        }