コード例 #1
0
        public async Task CreatPlot_ReturnNewObjectId()
        {
            var dbInMemoryOption = new DbContextOptionsBuilder <AgrotutorContext>()
                                   .UseInMemoryDatabase("CreatPlotWithImages").Options;

            using (var context = new AgrotutorContext(dbInMemoryOption))
            {
                var rep = new PlotRepository(context);
                IntializaPictureRepository();

                var plotController = new PlotsController(rep, _pictureRepository);

                var res = await plotController.CreatePlot(_newPlotWithImages) as OkObjectResult;

                Assert.IsNotNull(res);
                Assert.IsInstanceOfType(res.Value, typeof(PlotDto));
                Assert.IsTrue(((PlotDto)res.Value).Id > 0);
            }
        }
コード例 #2
0
        public async Task Can_Retrieve_By_ID()
        {
            var dbInMemoryOption = new DbContextOptionsBuilder <AgrotutorContext>()
                                   .UseInMemoryDatabase("RetrieveList").Options;

            using (var context = new AgrotutorContext(dbInMemoryOption))
            {
                if (!context.Plots.Any())
                {
                    var rep            = new PlotRepository(context);
                    var plotController = new PlotsController(rep, _pictureRepository);
                    await plotController.CreatePlot(_newPlotWithImages);

                    var resultOk = await plotController.GetPlotsById(1) as OkObjectResult;

                    Assert.IsNotNull(resultOk);
                    var result = resultOk.Value as PlotDto;
                    Assert.IsNotNull(result);
                    Assert.IsTrue(result.Id == 1);
                }
            }
        }