Example #1
0
        public void Initialize()
        {
            _fakeTherapistEventService = new Mock <ITherapistEventService>();
            _fakeTherapistEventService.SetupAllProperties();
            _fakeTherapistEventService.Setup(s => s.GetAllTherapistEvents(It.IsAny <TherapistEvent>())).ReturnsAsync(_testTherapistEvents);
            _fakeTherapistEventService.Setup(s => s.GetAllTherapistEventsByTherapistId(It.IsAny <TherapistEvent>())).ReturnsAsync(_testTherapistEvents);
            _fakeTherapistEventService.Setup(s => s.UpdateTherapistEvent(It.IsAny <int>(), It.IsAny <TherapistEvent>())).ReturnsAsync(_testTherapistEvents[0]);
            _fakeTherapistEventService.Setup(s => s.AddTherapistEvent(It.IsAny <TherapistEvent>())).ReturnsAsync(_testTherapistEvents[0]);
            _fakeTherapistEventService.Setup(s => s.DeleteTherapistEvent(It.IsAny <int>())).ReturnsAsync(_testTherapistEvents[0]);

            _testTherapistEventController = new TherapistEventController(_fakeTherapistEventService.Object);
        }
Example #2
0
        public void Initialize()
        {
            var options = new DbContextOptionsBuilder <CoreDbContext>()
                          .UseInMemoryDatabase(databaseName: "TherapistEventDatabase")
                          .Options;

            _testContext = new CoreDbContext(options);
            _testContext.Database.EnsureDeleted();
            _testUsers               = new List <User>();
            _testTherapistEvents     = new List <TherapistEvent>();
            _testTargetStartDateTime = new DateTime(2010, 2, 8);
            _testTargetEndDateTime   = new DateTime(2010, 2, 12);

            for (var i = 0; i < 8; i++)
            {
                var newUser = ModelFakes.UserFake.Generate();
                _testContext.Add(newUser);
                _testContext.SaveChanges();
                _testUsers.Add(ObjectExtensions.Copy(newUser));

                Permission newPermission = new Permission
                {
                    UserId = newUser.UserId,
                    Role   = "therapist"
                };
                _testContext.Add(newPermission);
                _testContext.SaveChanges();

                var newTherapistEvent = ModelFakes.TherapistEventFake.Generate();
                newTherapistEvent.TherapistId = newUser.UserId;

                if (i <= 2)
                {
                    newTherapistEvent.StartTime = _testTargetStartDateTime.AddDays(i);
                    newTherapistEvent.EndTime   = _testTargetEndDateTime.AddDays(-1 * i);
                }

                _testContext.Add(newTherapistEvent);
                _testContext.SaveChanges();
                _testTherapistEvents.Add(ObjectExtensions.Copy(newTherapistEvent));
            }

            _testNonTherapistUser = ModelFakes.UserFake.Generate();
            _testContext.Add(_testNonTherapistUser);
            _testContext.SaveChanges();
            _testUsers.Add(ObjectExtensions.Copy(_testNonTherapistUser));

            var newEdgeTherapistEvent = ModelFakes.TherapistEventFake.Generate();

            newEdgeTherapistEvent.TherapistId = _testUsers[0].UserId;
            newEdgeTherapistEvent.StartTime   = _testTargetStartDateTime.AddDays(-1);
            _testContext.Add(newEdgeTherapistEvent);
            _testContext.SaveChanges();
            _testTherapistEvents.Add(ObjectExtensions.Copy(newEdgeTherapistEvent));

            newEdgeTherapistEvent             = ModelFakes.TherapistEventFake.Generate();
            newEdgeTherapistEvent.TherapistId = _testUsers[0].UserId;
            newEdgeTherapistEvent.EndTime     = _testTargetEndDateTime.AddDays(1);
            _testContext.Add(newEdgeTherapistEvent);
            _testContext.SaveChanges();
            _testTherapistEvents.Add(ObjectExtensions.Copy(newEdgeTherapistEvent));

            _nonActiveTherapistEvent           = ModelFakes.TherapistEventFake.Generate();
            _nonActiveTherapistEvent.Active    = false;
            _nonActiveTherapistEvent.StartTime = _testTargetStartDateTime;
            _nonActiveTherapistEvent.EndTime   = _testTargetEndDateTime;
            _testContext.Add(_nonActiveTherapistEvent);
            _testContext.SaveChanges();
            _testTherapistEvents.Add(ObjectExtensions.Copy(_nonActiveTherapistEvent));

            _testTherapistEvent = new TherapistEvent
            {
                StartTime   = DateTime.MinValue,
                EndTime     = DateTime.MaxValue,
                TherapistId = _testUsers[0].UserId
            };

            _testTherapistEventService    = new TherapistEventService(_testContext);
            _testTherapistEventController = new TherapistEventController(_testTherapistEventService);
        }