コード例 #1
0
        public async Task MutantV1Controller_PostAsync_DtoNull_Succeeds()
        {
            //Arrange
            MutantV1Controller controller = GetMutantController();

            _mutantServiceMock.Setup(x => x.IsMutantAsync(It.IsAny <Human>())).ThrowsAsync(new ArgumentNullException()).Verifiable();

            //Action
            HttpResponseMessage result = await controller.PostAsync(null);

            //Asserts
            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
            _mutantServiceMock.Verify(x => x.IsMutantAsync(It.IsAny <Human>()), Times.Once);
        }
コード例 #2
0
        public async Task MutantV1Controller_PostAsync_WrongDto_Succeeds()
        {
            //Arrange
            MutantV1Controller controller = UnityConfig.Resolve <MutantV1Controller>();
            HumanV1Dto         dto        = new HumanV1Dto()
            {
                Dna = new string[] { "AAA", "CCC", "TTTXX" }
            };

            //Action
            HttpResponseMessage result = await controller.PostAsync(dto);

            //Asserts
            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
        }
コード例 #3
0
        public async Task MutantV1Controller_PostAsync_NonHandledException_Succeeds()
        {
            //Arrange
            MutantV1Controller controller = GetMutantController();
            HumanV1Dto         dto        = new HumanV1Dto();

            _mutantServiceMock.Setup(x => x.IsMutantAsync(It.IsAny <Human>())).ThrowsAsync(new Exception()).Verifiable();

            //Action
            HttpResponseMessage result = await controller.PostAsync(dto);

            //Asserts
            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.InternalServerError, result.StatusCode);
            _mutantServiceMock.Verify(x => x.IsMutantAsync(It.IsAny <Human>()), Times.Once);
        }
コード例 #4
0
        public async Task MutantV1Controller_PostAsync_ValidDtoFullyMapped_Succeeds()
        {
            //Arrange
            MutantV1Controller controller = GetMutantController();
            HumanV1Dto         dto        = new HumanV1Dto()
            {
                Dna = new string[] { "AAA", "CCC", "TTT" }
            };

            _mutantServiceMock.Setup(x => x.IsMutantAsync(It.IsAny <Human>())).ReturnsAsync(true).Verifiable();

            //Action
            HttpResponseMessage result = await controller.PostAsync(dto);

            //Asserts
            Assert.IsNotNull(result);
            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
            _mutantServiceMock.Verify(x => x.IsMutantAsync(It.IsAny <Human>()), Times.Once);
        }