Exemple #1
0
        public void Initialize()
        {
            _fakeService = new Mock <ITherapyService>();
            _fakeService.SetupAllProperties();
            _fakeService.Setup(s => s.GetAllTherapies()).ReturnsAsync(_testTherapies);
            _fakeService.Setup(s => s.GetAllAdls()).ReturnsAsync(_testAdls);
            _fakeService.Setup(s => s.GetAllTypes()).ReturnsAsync(_testTypes);
            _fakeService.Setup(s => s.GetTherapyByAbbreviation(It.IsAny <string>())).ReturnsAsync(_testTherapies[0]);
            _fakeService.Setup(s => s.GetTherapyByAdl(It.IsAny <string>())).ReturnsAsync(_testTherapies[0]);
            _fakeService.Setup(s => s.UpdateTherapy(It.IsAny <string>(), It.IsAny <Therapy>())).ReturnsAsync(_testTherapies[0]);
            _fakeService.Setup(s => s.AddTherapy(It.IsAny <Therapy>())).ReturnsAsync(_testTherapies[0]);
            _fakeService.Setup(s => s.DeleteTherapy(It.IsAny <string>())).ReturnsAsync(_testTherapies[0]);

            _testController = new TherapyController(_fakeService.Object);
        }
Exemple #2
0
        public void Initialize()
        {
            var options = new DbContextOptionsBuilder <CoreDbContext>()
                          .UseInMemoryDatabase(databaseName: "TherapyDatabase")
                          .Options;

            _testTherapyMains = new List <TherapyMain>();
            _testTherapies    = new List <Therapy>();
            _testAdls         = new List <string>();
            _testTypes        = new List <string>();
            _testContext      = new CoreDbContext(options);
            _testContext.Database.EnsureDeleted();

            for (var i = 0; i < 10; i++)
            {
                var newTherapyMain = ModelFakes.TherapyMainFake.Generate();
                _testTypes.Add(newTherapyMain.Type);
                _testContext.Add(newTherapyMain);
                _testContext.SaveChanges();
                _testTherapyMains.Add(ObjectExtensions.Copy(newTherapyMain));

                var newTherapy = ModelFakes.TherapyFake.Generate();
                newTherapy.Type = newTherapyMain.Type;
                _testAdls.Add(newTherapy.Adl);
                _testContext.Add(newTherapy);
                _testContext.SaveChanges();
                _testTherapies.Add(ObjectExtensions.Copy(newTherapy));
            }

            _nonActiveTherapy        = ModelFakes.TherapyFake.Generate();
            _nonActiveTherapy.Type   = _testTherapyMains[0].Type;
            _nonActiveTherapy.Active = false;
            _testContext.Add(_nonActiveTherapy);
            _testContext.SaveChanges();

            _testService    = new TherapyService(_testContext);
            _testController = new TherapyController(_testService);
        }