示例#1
0
        public void CreateDalConsultOperation_For_User_GetAll_Test()
        {
            #region === ARRANGE ===

            DtoUser        dtoUser       = new DtoUser(999, "", "", false);
            List <DtoUser> getMockResult = new List <DtoUser>()
            {
                dtoUser, dtoUser, dtoUser, dtoUser, dtoUser
            };
            int expected_length = getMockResult.Count;

            Mock <IReadOnlyRepository <DtoUser> > repositoryMock = new Mock <IReadOnlyRepository <DtoUser> >();
            repositoryMock.Setup(x => x.GetAll()).Returns(getMockResult);
            Mock <IRepositoryFactory> repositoryFactoryMock = new Mock <IRepositoryFactory>();
            repositoryFactoryMock.Setup(x => x.CreateReadOnlyUsersRepository()).Returns(repositoryMock.Object);

            DataBaseOperationsFactory dataBaseOperationsFactory = new DataBaseOperationsFactory();
            Mock <BusinessObject>     businessObjectMock        = new Mock <BusinessObject>(null);

            BusinessConsultEventArgs args = new BusinessConsultEventArgs(typeof(User))
            {
                businessConsultType = BusinessConsultType.GetAll
            };
            InfrastructureOperationsFactory factory = new InfrastructureOperationsFactory(repositoryFactoryMock.Object, dataBaseOperationsFactory);

            #endregion

            #region === ACT ===

            IInfrastructureOperation operation = factory.CreateDalConsultOperations(businessObjectMock.Object, args);
            operation.Execute();
            IEnumerable <User> result = (IEnumerable <User>)(args.result);

            #endregion

            #region === ASSERT ===

            repositoryMock.Verify(mock => mock.GetAll(), Times.Once());
            Assert.AreEqual(expected_length, result.Count());

            #endregion
        }
示例#2
0
        public void CreateDalConsultOperation_For_User_Get_Test()
        {
            #region === ARRANGE ===

            DtoUser dtoUser = new DtoUser(999, "", "", false);
            Mock <IReadOnlyRepository <DtoUser> > repositoryMock = new Mock <IReadOnlyRepository <DtoUser> >();
            repositoryMock.Setup(x => x.Get(It.IsAny <int>())).Returns(dtoUser);
            Mock <IRepositoryFactory> repositoryFactoryMock = new Mock <IRepositoryFactory>();
            repositoryFactoryMock.Setup(x => x.CreateReadOnlyUsersRepository()).Returns(repositoryMock.Object);

            DataBaseOperationsFactory dataBaseOperationsFactory = new DataBaseOperationsFactory();
            Mock <BusinessObject>     businessObjectMock        = new Mock <BusinessObject>(null);

            BusinessConsultEventArgs args = new BusinessConsultEventArgs(typeof(User))
            {
                businessConsultType = BusinessConsultType.Get, entityId = 1
            };
            InfrastructureOperationsFactory factory = new InfrastructureOperationsFactory(repositoryFactoryMock.Object, dataBaseOperationsFactory);

            #endregion

            #region === ACT ===

            IInfrastructureOperation operation = factory.CreateDalConsultOperations(businessObjectMock.Object, args);
            operation.Execute();
            User result = (User)(args.result.FirstOrDefault());

            #endregion

            #region === ASSERT ===

            repositoryMock.Verify(mock => mock.Get(It.IsAny <int>()), Times.Once());
            Assert.AreEqual(dtoUser.ID, result.id);

            #endregion
        }