public void AddUser_WhenTheUserNameAlreadyExists()
        {
            //Arrange

            myUserRepository.Expect(x => x.GetAll()).Return(new List <User> {
                new User {
                    UserName = "******"
                }
            }.AsQueryable()).Repeat.Once();
            myUnitOfWork.Expect(x => x.GetGenericRepository <User>()).Return(myUserRepository).Repeat.Once();
            myUnitOfWorkFactory.Expect(x => x.GetUnitOfWork()).Return(myUnitOfWork).Repeat.Once();

            var newUser = new User {
                UserName = "******", FirstName = "User", LastName = "Name", EmailAddress = "*****@*****.**"
            };

            var userService = new UserService
            {
                UnitOfWorkFactory = myUnitOfWorkFactory
            };

            //Act

            var result = userService.AddUser(newUser);

            //Asserts
            Assert.AreEqual(StatusCode.Error, result.StatusCode);
            Assert.AreEqual("The UserName already exists in the system.", result.StatusMessage);
            myUnitOfWork.VerifyAllExpectations();
            myUnitOfWorkFactory.VerifyAllExpectations();
            myUserRepository.VerifyAllExpectations();
        }
Exemple #2
0
        public void AddProject_WhenTheProjectNameAlreadyExists()
        {
            //Arrange
            myProjectRepository.Expect(x => x.GetAll()).Return(new List <Project> {
                new Project {
                    ProjectName = "test"
                }
            }.AsQueryable()).Repeat.Once();
            myUnitOfWork.Expect(x => x.GetGenericRepository <Project>()).Return(myProjectRepository).Repeat.Once();
            myUnitOfWorkFactory.Expect(x => x.GetUnitOfWork()).Return(myUnitOfWork).Repeat.Once();

            var newProyect = new Project {
                ProjectName = "test", Description = "asdasd"
            };

            var proyectService = new ProjectService
            {
                UnitOfWorkFactory = myUnitOfWorkFactory
            };

            //Act
            var result = proyectService.AddProject(newProyect);

            //Asserts
            Assert.AreEqual(StatusCode.Error, result.StatusCode);
            Assert.AreEqual("The project name already exits in the system.", result.StatusMessage);
            myUnitOfWork.VerifyAllExpectations();
            myUnitOfWorkFactory.VerifyAllExpectations();
            myProjectRepository.VerifyAllExpectations();
        }
        public void CallingCurrentFirstTimeShouldCreateNewUnitOfWork()
        {
            using (mocks.Record())
            {
                store.Expect(s => s.CurrentFor <NullDatabase>()).Return(null).Repeat.Twice();
                factory.Expect(f => f.Create());
                store.Expect(s => s.SetUnitOfWork <NullDatabase>(null)).IgnoreArguments();
            }

            using (mocks.Playback())
            {
                var unitOfWork = unitOfWorkManager.For <NullDatabase>();
            }
        }
Exemple #4
0
        public void AddTeam_WhenTheTeamNameAlreadyExists()
        {
            //Arrange

            myTeamRepository.Expect(x => x.GetAll()).Return(new List <Team> {
                new Team {
                    TeamId = 1, TeamName = "TeamName"
                }
            }.AsQueryable()).Repeat.Once();
            myUnitOfWork.Expect(x => x.GetGenericRepository <Team>()).Return(myTeamRepository).Repeat.Once();
            myUnitOfWorkFactory.Expect(x => x.GetUnitOfWork()).Return(myUnitOfWork).Repeat.Once();

            var newTeam = new Team {
                TeamName = "TeamName"
            };

            var teamService = new TeamService
            {
                UnitOfWorkFactory = myUnitOfWorkFactory
            };

            //Act

            var result = teamService.AddTeam(newTeam);

            //Asserts
            Assert.AreEqual(StatusCode.Error, result.StatusCode);
            Assert.AreEqual("The team name already exists in the system.", result.StatusMessage);
            myUnitOfWork.VerifyAllExpectations();
            myUnitOfWorkFactory.VerifyAllExpectations();
            myTeamRepository.VerifyAllExpectations();
        }
        public void UpdateActivity_WhenTheTeamDoesntExist()
        {
            //Arrange
            myActivityRepository.Expect(x => x.GetAll()).Return(new List <Activity> {
                new Activity {
                    ActivityId = 1, Description = "Activity 1"
                }
            }.AsQueryable()).Repeat.Once();
            myTeamRepository.Expect(x => x.GetAll()).Return(new List <Team> {
                new Team {
                    TeamId = 5, TeamName = "TestTeam"
                }
            }.AsQueryable()).Repeat.Once();
            myUnitOfWork.Expect(x => x.GetGenericRepository <Activity>()).Return(myActivityRepository).Repeat.Once();
            myUnitOfWork.Expect(x => x.GetGenericRepository <Team>()).Return(myTeamRepository).Repeat.Once();
            myUnitOfWorkFactory.Expect(x => x.GetUnitOfWork()).Return(myUnitOfWork).Repeat.Once();

            var newActivity = new Activity {
                ActivityId = 1, Description = "Activity 1.1", TeamId = 1
            };

            var ActivityService = new ActivityService
            {
                UnitOfWorkFactory = myUnitOfWorkFactory
            };

            //Act

            var result = ActivityService.UpdateActivity(newActivity);

            //Asserts
            Assert.AreEqual(StatusCode.Error, result.StatusCode);
            Assert.AreEqual("The team doesn't exist in the system.", result.StatusMessage);
            myUnitOfWork.VerifyAllExpectations();
            myUnitOfWorkFactory.VerifyAllExpectations();
            myActivityRepository.VerifyAllExpectations();
            myTeamRepository.VerifyAllExpectations();
        }