Ejemplo n.º 1
0
        public void TestEntities_ConfirmMapsIntoViewModel()
        {
            // Arrange
            _assetModelsRepository.Setup(x => x.GetAllModels()).Returns(GetModelsList);

            // Act
            var allModels      = _ModelsController.Get();
            var expectedResult = GetModelsList_ResultForMappingToVM();

            // Assert
            Assert.IsNotNull(allModels, "Result is null");
            allModels.ShouldBeEquivalentTo(expectedResult);
        }
Ejemplo n.º 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);
        }