示例#1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Reason = await _reasonService.GetReasonByIdAsync(id.Value);

            if (Reason == null)
            {
                return(NotFound());
            }
            return(Page());
        }
示例#2
0
        public void OnPostAsync_ReasonNull_DoesnotInvokeDeletionAndReturnsRedirect()
        {
            // Arrange
            A.CallTo(() => reasonServiceFake.GetReasonByIdAsync(A <int> .Ignored)).Returns(Task.FromResult <Reason>(null));

            // Act
            // get awaiter - get result so that we don't have to await this call, also safer than calling .Result
            var actual = _target.OnPostAsync(1).GetAwaiter().GetResult();

            // Assert
            // here we're making sure that no call to delete was made if the reason does not exist.
            A.CallTo(() => reasonServiceFake.DeleteReasonAsync(A <Reason> .Ignored)).MustNotHaveHappened();
            // this cast is so that we can be sure that the action result being returned is correct
            var result = actual as RedirectToPageResult;

            Assert.NotNull(result);
        }