예제 #1
0
        public void GetAllTasks_MockDbSetTasksAndContext_AndGetTask()
        {
            //assign
            MiniAutoFixture miniAutoFixture = new MiniAutoFixture();

            miniAutoFixture.Initialize();

            User user          = DbSetTools.CreateUser(11, miniAutoFixture);
            Task taskSpecified = DbSetTools.CreateTask(11, user, miniAutoFixture);

            List <Task> tasksCollection = DbSetTools.CreateTaskList(1, user, 10, miniAutoFixture)
                                          .Concat(new Task[] { taskSpecified })
                                          .ToList();


            IQueryable <Task> tasks = tasksCollection.AsQueryable();

            var mockDbSet = new Mock <DbSet <Task> >();

            mockDbSet.As <IQueryable <Task> >().Setup(m => m.Provider).Returns(tasks.Provider);
            mockDbSet.As <IQueryable <Task> >().Setup(m => m.Expression).Returns(tasks.Expression);
            mockDbSet.As <IQueryable <Task> >().Setup(m => m.ElementType).Returns(tasks.ElementType);
            mockDbSet.As <IQueryable <Task> >().Setup(m => m.GetEnumerator()).Returns(tasks.GetEnumerator());

            var mockContext = new Mock <OrganizerContext>();

            mockContext.Setup(c => c.Tasks).Returns(mockDbSet.Object);
            var            logger         = new Mock <ILogger <ViewRepository> >();
            ViewRepository viewRepository = new ViewRepository(mockContext.Object, logger.Object);


            // action
            TaskView taskView = viewRepository.GetTask(taskSpecified.Id);

            // assign
            Assert.Equal(taskSpecified.Id, taskView.Id);
            Assert.Equal(taskSpecified.Text, taskView.Text);
            Assert.Equal(taskSpecified.Date, taskView.Date);
            Assert.Equal(taskSpecified.Deleted, taskView.Deleted);
            Assert.Equal(taskSpecified.Done, taskView.Done);
        }
예제 #2
0
        public void MapTaskToView_WhenSetTask_ReturnTaskView()
        {
            //assign
            MiniAutoFixture miniAutoFixture = new MiniAutoFixture();

            miniAutoFixture.Initialize();

            int id = miniAutoFixture.CreateInt();

            Task task = DbSetTools.CreateTask(id, null, miniAutoFixture);

            //action
            TaskView taskView = ExtensionMethods.MapTaskToView(task);

            //assert
            Assert.Equal(task.Id, taskView.Id);
            Assert.Equal(task.Date, taskView.Date);
            Assert.Equal(task.Text, taskView.Text);
            Assert.Equal(task.Done, taskView.Done);
            Assert.Equal(task.Deleted, taskView.Deleted);
        }