예제 #1
0
        public void Get_ShouldBeOrderedByType()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var actual   = repo.Get();
            var expected = actual.OrderBy(i => i.Type);

            Assert.True(expected.SequenceEqual(actual));
        }
예제 #2
0
        public void Get_ShouldReturnAnEntityQueryableOfListItems()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var actual   = repo.Get();
            var expected = typeof(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable <ListItem>);

            Assert.IsType(expected, actual);
        }
예제 #3
0
        public void Delete_ShouldRemoveTheItemFromTheDatabase()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var idToDelete = 1;

            repo.Delete(idToDelete);

            Assert.Null(repo.Get(idToDelete));
        }
예제 #4
0
        public void Delete_ShouldKeepAllOtherItemsInTheDatebase()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var countBeforeDelete = repo.Get().Count();
            var idToDelete        = 1;

            repo.Delete(idToDelete);
            var countAfterDelete = repo.Get().Count();

            Assert.NotEqual(countBeforeDelete, countAfterDelete);
            Assert.True(countAfterDelete == (countBeforeDelete - 1));
        }
예제 #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ClauseService"/> class.
 /// </summary>
 public ClauseService(
     IListItemsRepository <Clause> clauseRepository,
     IListItemsRepository <Group> groupRepository,
     IListItemsRepository <Tag> tagRepository,
     IListItemsRepository <ExternalLink> externalLinksRepository,
     IListItemsRepository <Favourite> favouritesRepository) : base(clauseRepository)
 {
     _clauseRepository        = clauseRepository;
     _groupRepository         = groupRepository;
     _tagRepository           = tagRepository;
     _externalLinksRepository = externalLinksRepository;
     _favouritesRepository    = favouritesRepository;
 }
예제 #6
0
        public void GetById_ShouldReturnNullIfNoMatch()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var test1 = repo.Get(-1);
            var test2 = repo.Get(0);
            var test3 = repo.Get(4);


            Assert.Equal(test1, null);
            Assert.Equal(test2, null);
            Assert.Equal(test3, null);
        }
예제 #7
0
        public void Add_ShouldAssignANewId()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var addedItem = repo.Add(new ListItem
            {
                Title       = "Test Add",
                Description = "Testing adding an item",
                Importance  = "High",
                Type        = "Special",
                Created     = DateTime.Now,
                Updated     = DateTime.Now,
                Due         = DateTime.Now,
            });

            Assert.NotNull(addedItem.Id);
        }
예제 #8
0
        public void GetById_ShouldReturnTheCorrectItem()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var expectedId          = 2;
            var expectedTitle       = "Project";
            var expectedDescription = "Finish project by end of day on Saturday";
            var expectedImportance  = "High";
            var expectedType        = "Special";

            var actual = repo.Get(2);

            Assert.Equal(actual.Id, expectedId);
            Assert.Equal(actual.Title, expectedTitle);
            Assert.Equal(actual.Description, expectedDescription);
            Assert.Equal(actual.Importance, expectedImportance);
            Assert.Equal(actual.Type, expectedType);
        }
예제 #9
0
        public void Add_ShouldIncrementTheNumberOfItemsByOne()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();

            var startingCount = repo.Get().Count();

            repo.Add(new ListItem
            {
                Title       = "Test Add",
                Description = "Testing adding an item",
                Importance  = "High",
                Type        = "Special",
                Created     = DateTime.Now,
                Updated     = DateTime.Now,
                Due         = DateTime.Now,
            });

            var endingCount = repo.Get().Count();

            Assert.NotEqual(startingCount, endingCount);
            Assert.True(endingCount == (startingCount + 1));
        }
예제 #10
0
        public void Update_ShouldReturnAnEntityQueryableOfListItems()
        {
            IListItemsRepository repo = GetInMemoryListItemRepository();


            DateTime tomorrow = DateTime.Now;

            ListItem updateItem = new ListItem
            {
                Id          = 3,
                Title       = "Schedule Date Night",
                Description = "Pick a night to have date night",
                Importance  = "High",
                Type        = "Special",
                Created     = tomorrow,
                Updated     = tomorrow,
                Due         = DateTime.Now.AddDays(14),
            };

            var actual   = repo.Update(updateItem);
            var expected = typeof(Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable <ListItem>);

            Assert.IsType(expected, actual);
        }
 /// <summary>
 /// Creates an ExternalLinksService.
 /// </summary>
 public ExternalLinksService(IListItemsRepository<ExternalLink> externalLinksRepository)
 {
     _externalLinksRepository = externalLinksRepository;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="GroupService"/> class.
 /// </summary>
 public ListItemRequestService(IListItemsRepository <T> repository)
 {
     _repository = repository;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="FavouritesController"/> class.
 /// </summary>
 public FavouritesController(IListItemsRepository <Favourite> favouritesRepository)
     : base(favouritesRepository)
 {
 }
예제 #14
0
 public UnitOfWork(NotesDbContext notesContext)
 {
     _notesContext        = notesContext;
     _listsRepository     = new ListsRepository(_notesContext);
     _listItemsRepository = new ListItemsRepository(_notesContext);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ClausesController"/> class.
 /// </summary>
 /// <param name="clauseService">The clause service.</param>
 /// <param name="clauseRepository">The clause repository.</param>
 public ClausesController(ClauseService clauseService,
                          IListItemsRepository <Clause> clauseRepository)
     : base(clauseRepository)
 {
     _clauseService = clauseService;
 }
 /// <summary>
 /// Default Constructor
 /// </summary>
 /// <param name="repository">Repository to manage CRUD operations</param>
 protected ListItemsController(IListItemsRepository <T> repository)
 {
     Repository = repository;
 }
예제 #17
0
 /// <summary>
 /// Initializes a new instance of the <see cref="GroupsController"/> class.
 /// </summary>
 /// <param name="groupService">The group service.</param>
 /// <param name="groupRepository">The group repository.</param>
 public GroupsController(GroupService groupService, IListItemsRepository <Group> groupRepository) : base(groupRepository)
 {
     _groupService = groupService;
 }
예제 #18
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TagsController"/> class.
 /// </summary>
 public TagsController(IListItemsRepository <Tag> tagRepository) : base(tagRepository)
 {
 }
예제 #19
0
 public ListItemController(IListItemsRepository listItemsRepo)
 {
     this.listItemsRepo = listItemsRepo;
 }
예제 #20
0
 /// <summary>
 /// Creates an ExternalLinksService.
 /// </summary>
 public ExternalLinksService(IListItemsRepository <ExternalLink> externalLinksRepository)
 {
     _externalLinksRepository = externalLinksRepository;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ExternalLinksController"/> class.
 /// </summary>
 public ExternalLinksController(IListItemsRepository <ExternalLink> externalLinksRepository)
     : base(externalLinksRepository)
 {
     _externalLinksService = new ExternalLinksService(externalLinksRepository);
 }