public async Task GetWithParamsShouldReturnOkResult()
        {
            // Arrange
            var fakeSql = Substitute.For<IDatabase>();

            var fakeContext = Mock.Create<HttpContext>(Constructor.Mocked);
            Mock.Arrange(() => HttpContext.Current).Returns(fakeContext);

            var controller = new CampaignsController(fakeSql);

            // Act
            var result = await controller.Get(1);

            // Assert
            var viewResult = Assert.IsType<OkNegotiatedContentResult<Campaign>>(result);
            Assert.NotNull(viewResult);
        }
        public async Task PostShouldReturnOkResultWhenResultGreaterThanOne()
        {
            // Arrange
            var model = new Campaign();

            var fakeContext = Mock.Create<HttpContext>(Constructor.Mocked);
            Mock.Arrange(() => HttpContext.Current).Returns(fakeContext);

            var fakeSql = Substitute.For<IDatabase>();
            fakeSql.CreateAsync(model).Returns(Task.FromResult(1));

            var controller = new CampaignsController(fakeSql);

            // Act
            var result = await controller.Post(model);

            // Assert
            var viewResult = Assert.IsType<OkNegotiatedContentResult<Campaign>>(result);
            Assert.NotNull(viewResult);
        }
        public async Task DeleteShouldReturnOkResultWithModelId()
        {
            // Arrange
            var model = new Campaign();

            var fakeSql = Substitute.For<IDatabase>();
            fakeSql.DeleteAsync(model).ReturnsForAnyArgs(Task.FromResult(true));

            var controller = new CampaignsController(fakeSql);

            // Act
            var result = await controller.Delete(1);

            // Assert
            var viewResult = Assert.IsType<OkNegotiatedContentResult<int>>(result);
            Assert.Equal(viewResult.Content, 1);
        }
        public async Task DeleteShouldReturnBadRequestResultWhenResultFalse()
        {
            // Arrange
            var model = new Campaign();

            var fakeSql = Substitute.For<IDatabase>();
            fakeSql.DeleteAsync(model).ReturnsForAnyArgs(Task.FromResult(false));

            var controller = new CampaignsController(fakeSql);

            // Act
            var result = await controller.Delete(1);

            // Assert
            var viewResult = Assert.IsType<BadRequestResult>(result);
            Assert.NotNull(viewResult);
        }
        public async Task PutShouldReturnReturnOkResultWithModelDataUpdated()
        {
            // Arrange
            var model = new Campaign { Id = 1 };

            var datetimeoffset = DateTimeOffset.UtcNow;
            Mock.Arrange(() => DateTimeOffset.UtcNow).Returns(datetimeoffset);

            var userid = Guid.NewGuid().ToString();
            var fakeContext = Mock.Create<HttpContext>(Constructor.Mocked);
            Mock.Arrange(() => HttpContext.Current).Returns(fakeContext);
            Mock.Arrange(() => HttpContext.Current.User.Identity.GetUserId()).Returns(userid);

            var fakeSql = Substitute.For<IDatabase>();
            fakeSql.UpdateAsync(model).Returns(Task.FromResult(true));

            var controller = new CampaignsController(fakeSql);

            // Act
            var result = await controller.Put(2, model);

            // Assert
            var viewResult = Assert.IsType<OkNegotiatedContentResult<Campaign>>(result);
            Assert.Equal(viewResult.Content.UserId, userid);
            Assert.Equal(viewResult.Content.ModifiedDate, datetimeoffset);
            Assert.Equal(viewResult.Content.Id, 2);
        }
        public async Task PutShouldReturnInvalidModelStateResultWhenInvalidModel()
        {
            // Arrange
            var model = new Campaign();

            var fakeSql = Substitute.For<IDatabase>();
            fakeSql.CreateAsync(model).Returns(Task.FromResult(1));

            var controller = new CampaignsController(fakeSql)
            {
                Configuration = new HttpConfiguration()
            };
            controller.ModelState.AddModelError("FakeError", "This is a Fake Error!");

            // Act
            var result = await controller.Put(1, model);

            // Assert
            var viewResult = Assert.IsType<InvalidModelStateResult>(result);
            Assert.NotNull(viewResult);
        }
        public async Task PutShouldReturnBadRequestResultWhenResultFalse()
        {
            // Arrange
            var model = new Campaign();

            var fakeContext = Mock.Create<HttpContext>(Constructor.Mocked);
            Mock.Arrange(() => HttpContext.Current).Returns(fakeContext);

            var fakeSql = Substitute.For<IDatabase>();
            fakeSql.UpdateAsync(model).Returns(Task.FromResult(false));

            var controller = new CampaignsController(fakeSql);

            // Act
            var result = await controller.Put(1, model);

            // Assert
            var viewResult = Assert.IsType<BadRequestResult>(result);
            Assert.NotNull(viewResult);
        }