Example #1
0
        public async Task WhenExistingWebSiteIsDeletedThenThereShouldBeNoErrorsAndWebSiteShouldBeMarkedAsDeleted()
        {
            var webSiteToDelete = new WebSite
            {
                Id        = 1,
                IsDeleted = false
            };

            _webSiteRepository.Get(Arg.Any <Expression <Func <WebSite, bool> > >()).Returns(new List <WebSite>
            {
                webSiteToDelete
            }.AsQueryable());

            _webSiteManagerData.WebSiteRepository.Returns(_webSiteRepository);
            var serviceResult = await _webSiteService.DeleteAsync(1);

            await _webSiteManagerData.Received(1).SaveChangesAsync();

            Assert.That(serviceResult.HasErrors, Is.False, "There should be no errors");
            Assert.That(webSiteToDelete.IsDeleted, Is.True, "WebSite should be marked as deleted");
        }
        public async Task DeleteAsync_ShouldInvokeDeleteAsync()
        {
            // Arrange
            var existingWebSite = new WebSite();

            this.webSiteMockRepository.Setup(e => e.GetByIdAsync(It.IsAny <int>()))
            .Returns(Task.FromResult(existingWebSite));
            this.webSiteMockRepository.Setup(e => e.SoftDeleteAsync(existingWebSite))
            .Returns(Task.FromResult(existingWebSite.IsDeleted = true));

            // Act
            await webSiteService.DeleteAsync(It.IsAny <int>());

            // Assert
            this.webSiteMockRepository.Verify(
                x => x.SoftDeleteAsync(
                    It.Is <WebSite>(
                        y => y.IsDeleted == true)),
                Times.Once());
        }