示例#1
0
        public async Task AddNewItemAsIncompleteWithDueDate()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>().UseInMemoryDatabase(databaseName: "Test_AddNewItem").Options;

            using (var context = new ApplicationDbContext(options))
            {
                var service = new ToDoItemService(context);

                var fakeUser = new ApplicationUser
                {
                    Id       = "fake-000",
                    UserName = "******"
                };

                await service.AddItemAsync(new ToDoItem
                {
                    Title = "Testing?"
                }, fakeUser);
            }

            using (var context = new ApplicationDbContext(options))
            {
                var itemsInDatabase = await context.Items.CountAsync();

                Assert.Equal(1, itemsInDatabase);

                var item = await context.Items.FirstAsync();

                Assert.Equal("Testing?", item.Title);
                Assert.False(item.IsDone);

                var difference = DateTimeOffset.Now.AddDays(3) - item.DueAt;
                Assert.True(difference < TimeSpan.FromSeconds(1));
            }
        }
示例#2
0
        public async Task <ActionResult> Create(string listId, AddTodoItemModel addTodoItemModel)
        {
            DTO.ToDoItem toDoItem = new ToDoItem();
            toDoItem.Id              = Guid.NewGuid().ToString();
            toDoItem.Text            = addTodoItemModel.Text;
            toDoItem.IsCompleted     = false;
            toDoItem.IsDeleted       = false;
            toDoItem.CreatedDateTime = DateTime.Now;
            toDoItem.Deadline        = DateTime.Now.AddYears(100);
            toDoItem.TodoListId      = listId;

            ToDoItemService toDoItemService = new ToDoItemService(Session["MicrosoftAccessToken"] as string);


            try
            {
                // TODO: Add insert logic here
                await toDoItemService.InsertTodoItem(toDoItem);

                return(RedirectToAction("Index", new { listId }));
            }
            catch
            {
                return(View());
            }
        }
示例#3
0
        public async Task When_invoking_get_async_it_should_invoke_get_async_on_repository()
        {
            //Arrange
            var todoItem = new ToDoItem
            {
                Text        = "Sample text",
                IsCompleted = true
            };
            var toDoItemDto = new ToDoItemDto
            {
                Id          = todoItem.Id,
                Text        = todoItem.Text,
                IsCompleted = todoItem.IsCompleted,
                CreatedAt   = todoItem.CreatedAt
            };
            var todoRepositoryMock = new Mock <IRepository <ToDoItem> >();
            var mapperMock         = new Mock <IMapper>();

            mapperMock.Setup(x => x.Map <ToDoItemDto>(todoItem));
            var itemService = new ToDoItemService(todoRepositoryMock.Object, mapperMock.Object);

            todoRepositoryMock.Setup(x => x.GetById(todoItem.Id)).ReturnsAsync(todoItem);

            //Act
            var existToDoItemDto = await itemService.GetById(todoItem.Id);

            //Assert
            todoRepositoryMock.Verify(x => x.GetById(todoItem.Id), Times.Once());
            toDoItemDto.Should().NotBeNull();
            toDoItemDto.Text.Should().BeEquivalentTo(todoItem.Text);
            toDoItemDto.IsCompleted.Should().Be(todoItem.IsCompleted);
            todoItem.Id.Should().Be(todoItem.Id);
        }
示例#4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            //services.AddSingleton<ITodoItemService, ToDoItemService>();
            services.AddSingleton <ITodoItemService>(provider =>
            {
                var config     = Configuration.GetSection("MongoDBConfig").Get <MongoDbConfig>();
                var repository = new ToDoItemService(config);
                return(repository);
            });

            services.AddCors(options =>
            {
                options.AddPolicy("AllowAll", p =>
                {
                    p.AllowAnyOrigin()
                    .AllowAnyHeader()
                    .AllowAnyMethod();
                });
            });



            //services.AddSwaggerGen();
            services.AddSwaggerGen(c =>
            {
                var folder   = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var xmlFiles = Directory.GetFiles(folder, "*.xml").ToList();
                xmlFiles.ForEach(x => c.IncludeXmlComments(x));
            });
        }
示例#5
0
        [Fact]/**/
        public async Task AddNewItemAsIncompleteWhitDueDate()
        {
            await SetUp();

            //Se crea otro contexto, y se verifica que solo tenga un Item.
            //Luego se obtiene el primer item y se verifiva que el coincida el Tile
            //y que no este marcado como done.
            using (var CDB = new ApplicationDbContext(ODB.Options))
            {
                var itemsInDataBase = await CDB.Items.CountAsync();

                Assert.Equal(1, itemsInDataBase);

                var item = await CDB.Items.FirstAsync();

                Assert.Equal("Testing?", item.Title);
                //Assert.Equal(false, item.IsDone);
                Assert.True(false == item.IsDone);

                var difference = DateTimeOffset.Now.AddDays(3) - item.DueAt;
                Assert.True(difference < TimeSpan.FromSeconds(3));
            }
        }

        [Fact]/**/
        public async Task MarkDoneAnItemsWithGoodId()
        {
            await SetUp();

            //Se crea otro contexto, y se verifica que solo tenga un Item.
            //Luego se crea otro usuario (con el distinto Id) y se intenta marcar
            //como done el item almacenado en la base de datos usando MarkDoneAsync().
            using (var CDB = new ApplicationDbContext(ODB.Options))
            {
                var service       = new ToDoItemService(CDB);
                var otherFakeUser = new ApplicationUser {
                    Id = "fake-000", UserName = "******"
                };

                var itemsInDataBase = await CDB.Items.CountAsync();

                Assert.Equal(1, itemsInDataBase);

                var item = await CDB.Items.FirstAsync();

                Assert.False(item.IsDone);
                bool result = await service.MarkDoneAsync(item.Id, otherFakeUser);

                Assert.True(result);
                Assert.True(item.IsDone);
            }
        }
示例#6
0
        public async Task AddItemAsyncWithPropertyNameIsNullShouldThrowException()
        {
            var service   = new ToDoItemService(Context);
            var thirdItem = new ToDoItem();

            await Assert.ThrowsAsync <DbUpdateException>(() => service.AddItemAsync(thirdItem));
        }
示例#7
0
        // GET: AddTodoItem/Edit/5
        public async Task <ActionResult> Edit(string listId, string itemId)
        {
            ToDoItemService toDoItemService = new ToDoItemService(Session["MicrosoftAccessToken"] as string);
            var             item            = await toDoItemService.GetItemInfoByItemId(itemId);

            AddTodoItemModel addTodoItemModel = new AddTodoItemModel();

            addTodoItemModel.Id          = item.Id;
            addTodoItemModel.IsCompleted = item.IsCompleted;
            addTodoItemModel.Text        = item.Text;
            addTodoItemModel.TodoListId  = item.TodoListId;

            ViewBag.ListId = listId;

            if (await AccessAdmin(listId))
            {
                return(View(addTodoItemModel));
            }
            else if (await AccessEditor(listId))
            {
                return(View(addTodoItemModel));
            }
            else
            {
                return(View("AccessDenied"));
            }
        }
示例#8
0
        public async Task GetAsyncShouldReturnCorrectItem()
        {
            var service = new ToDoItemService(Context);

            var actualItem = await service.GetAsync(_firstItem.Id);

            Assert.Equal(_firstItem.Id, actualItem.Id);
        }
示例#9
0
        public async Task UpdateItemAsyncWithPropertyNameIsNullShouldThrowException()
        {
            var service      = new ToDoItemService(Context);
            var itemToUpdate = await service.GetAsync(_firstItem.Id);

            itemToUpdate.Name = null;

            await Assert.ThrowsAsync <DbUpdateException>(() => service.UpdateItemAsync(itemToUpdate));
        }
        public IToDoItemService CreateInstance()
        {
            // Instantiate to do item service with an MsSql mapper - hard coded for now
            MapperFactory mapperFactory = new MapperFactory(DA.Enumerations.DataStores.MsSql);

            IToDoItemService tis = new ToDoItemService(mapperFactory.GetToDoItemMapper());

            return(tis);
        }
示例#11
0
        public async Task GetItemsAsyncShouldReturnAllItems()
        {
            var service = new ToDoItemService(Context);

            var itemsFromService = await service.GetItemsAsync();

            Assert.Contains(itemsFromService, a => a.Id.Equals(_firstItem.Id));
            Assert.Contains(itemsFromService, a => a.Id.Equals(_secondItem.Id));
            Assert.Equal(_items.Count(), itemsFromService.Count());
        }
示例#12
0
        public async Task DeleteItemAsyncShouldDeleteItem()
        {
            var service = new ToDoItemService(Context);

            await service.DeleteItemAsync(_firstItem.Id);

            var itemsFromService = await service.GetItemsAsync();

            Assert.DoesNotContain(itemsFromService, item => item.Id.Equals(_firstItem.Id));
        }
示例#13
0
        /*[Fact]*/
        public async Task ReturnOwnItems()
        {
            //crea la base de datos en memoria.
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_GetIncompletItemsAsync").Options;

            //Crea el contexto necesario para realizar el test.
            //En este caso se crea el servicio ToDoItemService() y tres usuarios ficticios,
            //y se le van a agregar 5 items a cada uno.
            using (var context = new ApplicationDbContext(options))
            {
                var service = new ToDoItemService(context);

                for (int i = 0; i < 3; i++)
                {
                    string usr      = "******" + i;
                    string mail     = "fake" + i + "@example.com";
                    var    fakeUser = new ApplicationUser {
                        Id = usr, UserName = mail
                    };
                    for (int j = 0; j < 0; j++)
                    {
                        string itemTitle = "fake-00" + i;
                        var    item      = new ToDoItem {
                            Title = itemTitle
                        };
                        await service.AddItemAsync(item, fakeUser);
                    }
                }
            }

            //Se crea otro contexto, y se verifica que solo tenga un Item.
            //Luego se crea otro usuario y se intenta marcar como done el item almacenado
            //en la base de datos y creado por el primer usuario.
            //Se crea el servicio MarkDoneAsync() intentar marcar como completado al item
            //con el segundo usuario.
            using (var context = new ApplicationDbContext(options))
            {
                var service      = new ToDoItemService(context);
                var otherFkeUser = new ApplicationUser {
                    Id = "fake-000-ll", UserName = "******"
                };
                //var otherFkeUser = new ApplicationUser{ Id= "fake-000", UserName= "******"};

                var itemsInDataBase = await context.Items.CountAsync();

                Assert.Equal(1, itemsInDataBase);

                var item = await context.Items.FirstAsync();

                Assert.False(item.IsDone);
                Assert.False(await service.MarkDoneAsync(item.Id, otherFkeUser));
                Assert.False(item.IsDone);
            }
        }
示例#14
0
        internal ToDoItemOperations(ListView toDoItemsListView, ObservableCollection <ToDoItemView> toDoItemsCollection,
                                    int?projectId)
        {
            _projectId = projectId;

            _toDoItemsListView   = toDoItemsListView;
            _toDoItemsCollection = toDoItemsCollection;
            ItemService          = ToDoItemService.GetInstance();
            _tagService          = TagService.GetInstance();
            MinDate = DateTime.MinValue.AddYears(1753);
        }
示例#15
0
        public InboxPage()
        {
            InitializeComponent();

            _toDoItemsCollection = new ObservableCollection <ToDoItemView>();
            _itemService         = ToDoItemService.GetInstance();
            _operations          = new InboxToDoItemOperations(ToDoItemsListView, _toDoItemsCollection, null);

            FillCollection();

            ToDoItemsListView.ItemsSource = _toDoItemsCollection;
        }
示例#16
0
        public async Task UpdateItemAsyncShouldChangeName(string expectedName)
        {
            var service      = new ToDoItemService(Context);
            var itemToUpdate = await service.GetAsync(_firstItem.Id);

            itemToUpdate.Name = expectedName;

            await service.UpdateItemAsync(_firstItem);

            var updatedItem = await service.GetAsync(_firstItem.Id);

            Assert.Equal(expectedName, updatedItem.Name);
        }
示例#17
0
        public TodayPage()
        {
            InitializeComponent();

            ToDoItemsCollection = new ObservableCollection <ToDoItemView>();
            Service             = ToDoItemService.GetInstance();

            ToDoItemOperations = new TodayToDoItemOperations(ToDoItemsListView, ToDoItemsCollection, null);

            FillCollection();

            ToDoItemsListView.ItemsSource = ToDoItemsCollection;
        }
示例#18
0
        public UpcomingPage(MainWindow window)
        {
            InitializeComponent();

            _upcomingItemsCollection = new List <UpcomingToDoItems>();
            _itemService             = ToDoItemService.GetInstance();
            _tagService = TagService.GetInstance();
            _parent     = window;

            FillCollection();

            UpcomingListView.ItemsSource = _upcomingItemsCollection;
        }
示例#19
0
        private void RefreshButton_OnClick(object sender, RoutedEventArgs e)
        {
            Service.RefreshContext();

            _parent.Refresh();

            TagService.GetInstance().RefreshRepositories();
            ProjectService.GetInstance().RefreshRepositories();
            ToDoItemService.GetInstance().RefreshRepositories();

            PagesListView_OnSelectionChanged(null, null);

            ShowInvitations();
        }
示例#20
0
        public LogbookPage(MainWindow window)
        {
            InitializeComponent();

            _toDoItemsCollection = new ObservableCollection <LogbookToDoItem>();
            _itemService         = ToDoItemService.GetInstance();
            _tagService          = TagService.GetInstance();
            _parent  = window;
            _minDate = DateTime.MinValue.AddYears(1753);

            FillCollection();

            ToDoItemsListView.ItemsSource = _toDoItemsCollection;
        }
示例#21
0
        public LogbookPage(MainWindow window)
        {
            InitializeComponent();

            ToDoItemsCollection = new ObservableCollection <LogbookToDoItem>();
            ItemService         = ToDoItemService.GetInstance();
            TagService          = TagService.GetInstance();
            MainWindow          = window;
            MinDate             = DateTime.MinValue.AddYears(DateTime.Now.Year);

            FillCollection();

            ToDoItemsListView.ItemsSource = ToDoItemsCollection;
        }
示例#22
0
        public async Task AddItemAsyncShouldAddItem()
        {
            var service   = new ToDoItemService(Context);
            var thirdItem = new ToDoItem()
            {
                Name = "Third Item"
            };

            await service.AddItemAsync(thirdItem);

            var itemsFromService = await service.GetItemsAsync();

            Assert.Contains(itemsFromService, a => a.Id.Equals(thirdItem.Id));
            Assert.Equal(3, itemsFromService.Count());
        }
        public async Task MarkDoneAnItemsWithGoodId()
        {
            //crea la base de datos en memoria.
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_MarkDoneWrongUser").Options;

            //Crea el contexto necesario para realizar el test.
            //En este caso se crea el servicio ToDoItemService() y un usuario ficticio,
            //y con esto se agrega un item a la base de datos.
            using (var context = new ApplicationDbContext(options))
            {
                var service  = new ToDoItemService(context);
                var fakeUser = new ApplicationUser {
                    Id = "fake-000", UserName = "******"
                };
                var item = new ToDoItem {
                    Title = "Testing?"
                };
                await service.AddItemAsync(item, fakeUser);

                //await service.MarkDoneAsync(item.Id, fakeUser);
            }

            //Se crea otro contexto, y se verifica que solo tenga un Item.
            //Luego se crea otro usuario y se intenta marcar como done el item almacenado
            //en la base de datos y creado por el primer usuario.
            //Se crea el servicio MarkDoneAsync() intentar marcar como completado al item
            //con el segundo usuario.
            using (var context = new ApplicationDbContext(options))
            {
                var service      = new ToDoItemService(context);
                var otherFkeUser = new ApplicationUser {
                    Id = "fake-000-ll", UserName = "******"
                };
                //var otherFkeUser = new ApplicationUser{ Id= "fake-000", UserName= "******"};

                var itemsInDataBase = await context.Items.CountAsync();

                Assert.Equal(1, itemsInDataBase);

                var item = await context.Items.FirstAsync();

                Assert.False(item.IsDone);
                Assert.False(await service.MarkDoneAsync(item.Id, otherFkeUser));
                Assert.False(item.IsDone);
            }
        }
示例#24
0
        public async Task When_adding_new_todoItem_it_should_invoke_add_async_on_repository()
        {
            //Arrange
            var todoRepositoryMock = new Mock <IRepository <ToDoItem> >();
            var mapperMock         = new Mock <IMapper>();
            var itemService        = new ToDoItemService(todoRepositoryMock.Object, mapperMock.Object);
            var itemCommandToAdd   = new ToDoItemToAdd
            {
                Text = "Sample text"
            };

            //Act
            await itemService.AddToDoItem(itemCommandToAdd);

            //Assert
            todoRepositoryMock.Verify(x => x.AddAsync(It.IsAny <ToDoItem>()), Times.Once());
        }
示例#25
0
 private async Task SetUp()
 {
     //Crea el contexto (conexion con la base de datos) para poder crear
     //el servicio ToDoItemService. Luego se crea un usuario
     //ficticio con el que se agrega un item a la base de datos mediante AddItemAsync().
     using (var context = new ApplicationDbContext(ODB.Options))
     {
         var service  = new ToDoItemService(context);
         var fakeUser = new ApplicationUser {
             Id = "fake-000", UserName = "******"
         };
         var item = new ToDoItem {
             Title = "Testing?"
         };
         await service.AddItemAsync(item, fakeUser);
     }
 }
示例#26
0
        public async Task AddNewItemAsIncompleteWithDueDate()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "Test_AddNewItem")
                          .Options;

            // Set up a context (connection to the "DB")
            // for writing
            using (var context = new ApplicationDbContext(options))
            {
                var service = new ToDoItemService(context);

                var fakeUser = new ApplicationUser
                {
                    Id       = "fake-000",
                    UserName = "******"
                };

                await service.AddItemAsync(new NewToDoItem
                {
                    Title = "Testing?",
                    DueAt = DateTimeOffset.Now.AddDays(3)
                }, fakeUser);
            }

            // Use a separate context to read data back from the "DB"
            using (var context = new ApplicationDbContext(options))
            {
                var itemsInDatabase =
                    await context.Items
                    .CountAsync();

                Assert.Equal(1, itemsInDatabase);

                var item = await context.Items.FirstAsync();

                Assert.Equal("Testing?", item.Title);
                Assert.False(item.IsDone);

                // Item should be due 3 days
                // from now (give or take a second)
                var difference =
                    DateTimeOffset.Now.AddDays(3) - item.DueAt;
                Assert.True(difference < TimeSpan.FromSeconds(50));
            }
        }
示例#27
0
        public SharedProjectPage(MainWindow window, int projectId, string projectName)
        {
            InitializeComponent();

            ProjectNameLabel.Content = projectName;

            MainWindow          = window;
            MembersIsLoaded     = false;
            ProjectId           = projectId;
            ToDoItemsCollection = new ObservableCollection <ToDoItemView>();
            ItemService         = ToDoItemService.GetInstance();
            ProjectService      = ProjectService.GetInstance();
            ToDoItemOperations  = new SharedToDoItemOperations(ToDoItemsListView, ToDoItemsCollection, ProjectId);

            FillCollection();

            ToDoItemsListView.ItemsSource = ToDoItemsCollection;
        }
示例#28
0
        public SharedProjectPage(MainWindow parent, int projectId, string projectName)
        {
            InitializeComponent();

            ProjectNameLabel.Content = projectName;

            _parent              = parent;
            _membersLoaded       = false;
            _projectId           = projectId;
            _toDoItemsCollection = new ObservableCollection <ToDoItemView>();
            _itemService         = ToDoItemService.GetInstance();
            _projectService      = ProjectService.GetInstance();
            _operations          =
                new SharedToDoItemOperations(ToDoItemsListView, _toDoItemsCollection, _projectId);

            FillCollection();

            ToDoItemsListView.ItemsSource = _toDoItemsCollection;
        }
示例#29
0
        public async Task <ActionResult> Delete(string listId, string itemId, AddTodoItemModel addTodoItemModel)
        {
            try
            {
                // TODO: Add delete logic here
                ToDoItemService toDoItemService = new ToDoItemService(Session["MicrosoftAccessToken"] as string);
                DTO.ToDoItem    tdItem          = await toDoItemService.GetItemInfoByItemId(itemId);

                tdItem.IsDeleted = true;

                await toDoItemService.UpdateTodoItem(tdItem);


                return(RedirectToAction("Index", new { listId }));
            }
            catch
            {
                return(View());
            }
        }
示例#30
0
        public async Task <ActionResult> Edit(string listId, string itemId, AddTodoItemModel addTodoItemModel)
        {
            try
            {
                string          accessToken     = Session["MicrosoftAccessToken"] as string;
                ToDoItemService toDoItemService = new ToDoItemService(accessToken);

                // TODO: Add update logic here
                DTO.ToDoItem tdItem = await toDoItemService.GetItemInfoByItemId(itemId);

                //tdItem.Id = itemId;
                tdItem.Text        = addTodoItemModel.Text;
                tdItem.IsCompleted = addTodoItemModel.IsCompleted;
                //tdItem.IsDeleted = false;
                //tdItem.TodoListId = listId;


                //ToDoItemService toDoItemService = new ToDoItemService(Session["MicrosoftAccessToken"] as string);
                await toDoItemService.UpdateTodoItem(tdItem);

                var allListItems = await toDoItemService.GetTodoListsItems(listId);

                if (allListItems.All(i => i.IsCompleted))
                {
                    var todoListService = new ToDoListService(accessToken);
                    var list            = await todoListService.GetListById(listId);

                    list.IsCompleted = true;
                    await todoListService.UpdateTodoList(list);
                }

                ViewBag.ListId = listId;
                //ViewBag.ItemId = itemId;

                return(RedirectToAction("Index", new { listId }));
            }
            catch
            {
                return(View());
            }
        }