Exemple #1
0
        public async Task Delete_Invalid_NullReferenceException_Test()
        {
            _annualReportService.Setup(a => a.DeleteAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <int>()))
            .Throws(new NullReferenceException());

            _loggerService.Setup(l => l.LogError(It.IsAny <string>()));

            _localizer
            .Setup(s => s["NotFound"])
            .Returns(GetNotFound());

            AnnualReportController annualController = CreateAnnualReportController;

            // Act

            var result = await annualController.Cancel(5);


            // Assert
            Assert.NotNull(result);
            _localizer
            .Verify(s => s["NotFound"]);
            _loggerService.Verify(l => l.LogError(It.IsAny <string>()));
            Assert.IsInstanceOf <ObjectResult>(result);
        }
Exemple #2
0
        public async Task Cancel_Invalid_NullReferenceException_Test()
        {
            _annualReportService.Setup(a => a.CancelAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <int>()))
            .Throws(new NullReferenceException());

            _loggerService.Setup(l => l.LogError(It.IsAny <string>()));

            _localizer
            .Setup(s => s["NotFound"])
            .Returns(GetNotFound());

            AnnualReportController annualController = CreateAnnualReportController;

            // Act

            var result = await annualController.Cancel(5);

            var expected = StatusCodes.Status404NotFound;
            var actual   = (result as ObjectResult).StatusCode;

            // Assert
            Assert.NotNull(result);
            Assert.AreEqual(actual, expected);
            _localizer
            .Verify(s => s["NotFound"]);
            _loggerService.Verify(l => l.LogError(It.IsAny <string>()));
            Assert.IsInstanceOf <ObjectResult>(result);
        }
Exemple #3
0
        public async Task Cancel_Invalid_UnAuthorisedException_Test()
        {
            _annualReportService.Setup(a => a.CancelAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <int>()))
            .Throws(new UnauthorizedAccessException());

            _userManagerService.Setup(a => a.GetUserIdAsync(It.IsAny <ClaimsPrincipal>()));

            _loggerService.Setup(l => l.LogError(It.IsAny <string>()));

            _localizer
            .Setup(s => s["NoAccess"])
            .Returns(GetNoAccess());

            AnnualReportController annualController = CreateAnnualReportController;

            // Act
            var result = await annualController.Cancel(5);

            var expected = StatusCodes.Status403Forbidden;
            var actual   = (result as ObjectResult).StatusCode;

            // Assert
            Assert.AreEqual(actual, expected);
            Assert.NotNull(result);
            _localizer
            .Verify(s => s["NoAccess"]);
            _loggerService.Verify(l => l.LogError(It.IsAny <string>()));
            Assert.IsInstanceOf <ObjectResult>(result);
        }
Exemple #4
0
        public async Task Cancel_Valid_Test()
        {
            _annualReportService.Setup(a => a.CancelAsync(It.IsAny <ClaimsPrincipal>(), It.IsAny <int>()));

            _userManagerService.Setup(a => a.GetUserIdAsync(It.IsAny <ClaimsPrincipal>()));

            _loggerService.Setup(l => l.LogInformation(It.IsAny <string>()));

            _localizer
            .Setup(s => s["Canceled"])
            .Returns(GetCanceled());

            AnnualReportController annualController = CreateAnnualReportController;

            // Act

            var result = await annualController.Cancel(5);

            var expected = StatusCodes.Status200OK;
            var actual   = (result as ObjectResult).StatusCode;

            // Assert
            Assert.AreEqual(actual, expected);
            Assert.NotNull(result);
            _localizer
            .Verify(s => s["Canceled"]);
            Assert.IsInstanceOf <ObjectResult>(result);
        }