public void InitializeTest()
 {
     _mockScheduleRepository     = MockRepository.GenerateMock <IScheduleRepository>();
     _scheduleController         = new ScheduleController(_mockScheduleRepository);
     _templateScheduleController = new TemplateScheduleController();
     _templateShiftController    = new TemplateShiftController(new TemplateShiftRepository());
 }
Ejemplo n.º 2
0
        public void Save_ThrowsExceptionOnSave_SavesLog()
        {
            var user = new User()
            {
                Name  = "John",
                Email = "*****@*****.**"
            };

            var exception = new Exception("Fail to connect to database");

            var emailValidation = MockRepository.GenerateStub <IEmailValidation>();
            var userRepository  = MockRepository.GenerateStub <IUserRepository>();
            var logService      = MockRepository.GenerateMock <ILogService>();

            emailValidation.Stub(p => p.isValid(It.IsAny <string>())).Return(true);
            userRepository.Stub(p => p.Save(It.Is <User>(u => u.Equals(user)))).Throw(exception);
            logService.Expect(p => p.LogError(It.Is <Exception>(e => e.Equals(exception))));

            var userService = new UserService(userRepository, emailValidation);

            userService.LogService = logService;

            userService.Save(user);

            userRepository.VerifyAllExpectations();
        }
Ejemplo n.º 3
0
        public void Rhino_onSpecificDrugsRetrieved_WhenEventRaised_DrugServiceListens()
        {
            // Arrange
            var mockDrugService = MockRepository.GenerateMock <IDrugService>();

            _dataAccess.SpecificDrugRetrievedEvent += mockDrugService.OnSpecificDrugsRetrieved;

            // Act
            _dataAccess.GetSpecificDrugs(_drugIds);

            // Assert
            mockDrugService.AssertWasCalled(ds => ds.OnSpecificDrugsRetrieved(Arg <object> .Is.Equal(_dataAccess), Arg <SpecificDrugRetrievedArgs> .Matches(a => Equals(a.DrugIds, _drugIds))));
        }
Ejemplo n.º 4
0
        public void Rhino_onDrugRetrieved_WhenEventRaised_HaveDrugsBeenReceivedIsSet()
        {
            // Arrange
            var mockDataAccess       = MockRepository.GenerateMock <IDataAccess>();
            var mockThirdPartyAccess = MockRepository.GenerateMock <IThirdPartyDataAccess>();

            var drugService = new DrugService(mockDataAccess, mockThirdPartyAccess);

            drugService.HaveDrugsBeenReceived.ShouldBeFalse();

            // Act
            // Assert
            mockThirdPartyAccess.Raise(tpa => tpa.OnDrugsRetrievedEvent += null, mockThirdPartyAccess, new DrugsRetrievedArgs {
                HaveDrugsBeenRetrieved = true
            });
            drugService.HaveDrugsBeenReceived.ShouldBeTrue();
        }
Ejemplo n.º 5
0
        public void Rhino_Exception()
        {
            // Arrange
            var mockDataAccess = MockRepository.GenerateMock <IDataAccess>();

            mockDataAccess.Stub(da => da.GetSpecificDrugs(Arg <List <int> > .Is.Anything)).Throw(new ArgumentException());

            var mockThirdPartyAccess = MockRepository.GenerateMock <IThirdPartyDataAccess>();

            var drugService = new DrugService(mockDataAccess, mockThirdPartyAccess);

            // Act
            Action getSpecificDrugs = () => drugService.GetSpecificDrugs(Arg <List <int> > .Is.Anything);

            // Assert
            getSpecificDrugs.ShouldThrow <ArgumentException>();
        }
Ejemplo n.º 6
0
        public void GetById_ValidId_ReturnsUser()
        {
            int id = 1;

            var user = new User()
            {
                Id = id
            };

            var userRepository = MockRepository.GenerateMock <IUserRepository>();

            userRepository.Expect(p => p.GetById(id)).Return(user);

            var userService = new UserService(userRepository, null);

            var r = userService.GetById(id);

            Assert.AreEqual(user, r);
            userRepository.VerifyAllExpectations();
        }
Ejemplo n.º 7
0
        public void Save_ValidUser_Success()
        {
            var user = new User()
            {
                Name  = "John",
                Email = "*****@*****.**"
            };

            var emailValidation = MockRepository.GenerateStub <IEmailValidation>();
            var userRepository  = MockRepository.GenerateMock <IUserRepository>();

            emailValidation.Stub(p => p.isValid(It.IsAny <string>())).Return(true);
            userRepository.Expect(p => p.Save(It.Is <User>(u => u.Equals(user))));

            var userService = new UserService(userRepository, emailValidation);

            userService.Save(user);

            userRepository.VerifyAllExpectations();
        }
Ejemplo n.º 8
0
        public void Should_invoke_the_isautheticated_and_roles_functions()
        {
            // Arrange
            var context = MockRepository.GenerateMock <ISecurityContext>();

            context.Expect(x => x.CurrenUserAuthenticated()).Return(true).Repeat.Once();
            context.Expect(x => x.CurrenUserRoles()).Return(new List <object> {
                UserRole.Owner
            }.ToArray()).Repeat.Once();
            context.Replay();

            var policyContainer = new PolicyContainer(TestDataFactory.ValidControllerName, TestDataFactory.ValidActionName, TestDataFactory.CreateValidPolicyAppender());

            policyContainer.AddPolicy(new TestPolicy());

            // Act
            policyContainer.EnforcePolicies(context);

            // Assert
            context.VerifyAllExpectations();
        }
        public void Rhino_GetTheDrugs()
        {
            // Arrange
            var mockDataAccess = MockRepository.GenerateMock <IDataAccess>();

            mockDataAccess.Expect(da => da.GetAllTheDrugs()).Return(_fakeDrugList);

            var mockThirdPartyAccess = MockRepository.GenerateMock <IThirdPartyDataAccess>();

            mockThirdPartyAccess.Expect(tpa => tpa.GetThirdPartyDrugInfo(_fakeDrug1)).Return(FakeThirdPartyInfo1);
            mockThirdPartyAccess.Expect(tpa => tpa.GetThirdPartyDrugInfo(_fakeDrug2)).Return(FakeThirdPartyInfo2);
            mockThirdPartyAccess.Expect(tpa => tpa.GetThirdPartyDrugInfo(_fakeDrug3)).Return(FakeThirdPartyInfo3);

            var drugService = new DrugService(mockDataAccess, mockThirdPartyAccess);

            // Act
            var actualDrugs = drugService.GetTheDrugs();

            // Assert
            actualDrugs.Count().ShouldBe(3);

            mockDataAccess.AssertWasCalled(da => da.GetAllTheDrugs(), options => options.Repeat.Times(1));
            mockThirdPartyAccess.AssertWasCalled(da => da.GetThirdPartyDrugInfo(Arg <Drug> .Is.Anything), options => options.Repeat.Times(3));
        }
 public void TestInitialize()
 {
     _mockScheduleRepository  = MockRepository.GenerateMock <IScheduleShiftRepository>();
     _scheduleShiftController = new ScheduleShiftController(_mockScheduleRepository);
 }