예제 #1
0
        public MappingProfileTests()
        {
            var mockMapper = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile(new MappingProfile());
            });

            _mapper = mockMapper.CreateMapper();

            _createBotModel = new CreateBotModel
            {
                IP       = "155.223.25.67",
                Platform = "Linux",
                Status   = "Waiting",
                BotnetId = 1
            };
            _updateBotModel = new UpdateBotModel
            {
                Id       = 1,
                IP       = "155.223.25.67",
                Platform = "Linux",
                Status   = "Waiting",
                BotnetId = 1
            };
        }
예제 #2
0
        public BotsControllerTests()
        {
            var mapper = A.Fake <IMapper>();

            _mediator = A.Fake <IMediator>();
            _testee   = new BotsController(mapper, _mediator);

            _createBotModel = new CreateBotModel
            {
                IP       = "155.223.25.67",
                Platform = "Linux",
                Status   = "Waiting",
                BotnetId = 1
            };
            _updateBotModel = new UpdateBotModel
            {
                Id       = _id,
                IP       = "155.223.25.67",
                Platform = "Linux",
                Status   = "Waiting",
                BotnetId = 1
            };
            var bot = new Bot
            {
                Id       = _id,
                IP       = "155.223.25.67",
                Platform = "Linux",
                Status   = "Waiting",
                BotnetId = 1
            };

            A.CallTo(() => mapper.Map <Bot>(A <Bot> ._)).Returns(bot);
            A.CallTo(() => _mediator.Send(A <CreateBotCommand> ._, default)).Returns(bot);
            A.CallTo(() => _mediator.Send(A <UpdateBotCommand> ._, default)).Returns(bot);
        }
예제 #3
0
        public async void Put_WhenBotDoesNotExist_ShouldReturnNotFound()
        {
            var updateBotModel = new UpdateBotModel {
                Id = 0
            };
            var result = await _testee.PutBot(updateBotModel);

            (result.Result as StatusCodeResult)?.StatusCode.Should().Be((int)HttpStatusCode.NotFound);
        }
예제 #4
0
        public async Task <ActionResult <Bot> > PutBot([FromBody] UpdateBotModel updateBotModel)
        {
            try
            {
                var bot = await _mediator.Send(new GetBotByIdQuery
                {
                    Id = updateBotModel.Id
                });

                if (bot == null)
                {
                    return(NotFound());
                }

                return(await _mediator.Send(new UpdateBotCommand
                {
                    Bot = _mapper.Map(updateBotModel, bot)
                }));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }