コード例 #1
0
        public void TestAddingNewModels_DoesntReturnNull_ReturnsNewModelsID()
        {
            // Arrange
            _assetModelsRepository.Setup(x => x.CreateModel(It.IsAny <AssetManager_Models>()))
            .Returns(PostModels_ResultFromPostReturnInt());
            // Act
            var postTaskTypeID = _ModelsController.Post(PostModels());

            // Assert
            Assert.IsNotNull(postTaskTypeID, "Result is null");
            postTaskTypeID.ShouldBeEquivalentTo(1);
        }
コード例 #2
0
        public async void PostModel()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString())
                          .Options;

            await using var context = new ApplicationDbContext(options);
            IModelRepository   repository = new ModelRepository <ApplicationDbContext>(context);
            IModelService      service    = new ModelService(repository, AuditMock.Object, _mapper);
            IApiErrorResources error      = new ApiErrorResources();
            var controller = new ModelsController(service, error, _mapper);

            //checking to see if post works
            var createModelApiDto = GenerateCreateModelApiDto();
            var sign = await controller.Post(createModelApiDto);

            var result = await context.Models.FirstOrDefaultAsync();

            // weak assertion. TODO: assert property-for-property equality
            Assert.NotNull(result);



            //checking to see if get works
            var id    = Guid.NewGuid();
            var model = GenerateModel(id);

            var jsonString = Newtonsoft.Json.JsonConvert.SerializeObject(model);

            await context.Models.AddAsync(model);

            var numAdded = await context.SaveChangesAsync();

            var getModel = await controller.Get(model.Id);

            // weak assertion. TODO: assert property-for-property equality
            Assert.NotNull(getModel.Result);
        }
コード例 #3
0
        public async void AddModel_ReturnModelCreated()
        {
            // Arrange
            var mockRepo = new Mock <IVehicleCatalogRepository>();

            mockRepo.Setup(repo => repo.SaveAll())
            .Returns(Task.FromResult <bool>(true));
            var         mapper     = _dependencyFixture.ServiceProvider.GetService <IMapper>();
            var         logger     = Mock.Of <ILogger <ModelsController> >();
            var         controller = new ModelsController(mockRepo.Object, mapper, logger);
            ModelForNew newModel   = new ModelForNew()
            {
                name = "Fake", brandId = 1
            };

            // Act
            var result = await controller.Post(newModel);

            // Assert
            var okResult    = Assert.IsType <CreatedAtRouteResult>(result);
            var returnValue = Assert.IsType <string>(okResult.Value);

            Assert.Equal("Model created.", returnValue);
        }