Ejemplo n.º 1
0
        public async void Returns_OkObjectResult200AndCreatedNote_when_NoteCreated()
        {
            IDatabaseContext    databaseContext     = DatabaseTestHelper.GetContext();
            MapperConfiguration mapperConfiguration = new MapperConfiguration(conf =>
            {
                conf.AddProfile(new Note_to_NoteOut());
            });
            IMapper mapper = mapperConfiguration.CreateMapper();

            INotesService notesService = new NotesService(databaseContext, mapper);

            NotePost newNotePost = new NotePost
            {
                Title   = "Note's title",
                Content = "Note's content"
            };

            StatusCode <NoteOut> status = await notesService.PostNoteByUser(newNotePost, ADMIN_USERNAME);

            Assert.NotNull(status);
            Assert.Equal(StatusCodes.Status200OK, status.Code);
            Assert.NotNull(status.Body);
            Assert.Equal(newNotePost.Title, status.Body.Title);
            Assert.Equal(newNotePost.Content, status.Body.Content);
            Assert.Equal(DAO.Models.Base.ResourceType.NOTE, status.Body.ResourceType);
            Assert.True(databaseContext.Notes.AnyAsync(_ => _.ID == status.Body.ID).Result);
        }
Ejemplo n.º 2
0
        public async Task DeleteCaseByIdTests()
        {
            var listOfCases = new List <Case>()
            {
                new Case()
                {
                    Id = "1",
                },
                new Case()
                {
                    Id = "2",
                },
                new Case()
                {
                    Id = "3",
                },
            };
            var mockCasesRepo = new Mock <IDeletableEntityRepository <Case> >();
            var mockNotesRepo = new Mock <IDeletableEntityRepository <Note> >();

            mockCasesRepo.Setup(r => r.AllAsNoTracking()).Returns(listOfCases.AsQueryable);
            mockCasesRepo.Setup(x => x.Delete(It.IsAny <Case>())).Callback(
                (Case caseToDelete) => listOfCases
                .Where(x => x.Id == caseToDelete.Id)
                .FirstOrDefault().IsDeleted = true);

            var notesService = new NotesService(mockNotesRepo.Object);
            var casesService = new CasesService(mockCasesRepo.Object, notesService);

            await casesService.DeleteCaseByIdAsync("1");

            Assert.Equal(3, listOfCases.Count());
            Assert.True(listOfCases.Where(x => x.Id == "1").FirstOrDefault().IsDeleted);
        }
Ejemplo n.º 3
0
        public async Task CreateNoteTests()
        {
            var newNote = new NoteViewModel()
            {
                Content        = "new note",
                CaseId         = "1",
                OriginalPoster = "poster",
            };

            var notesList = new List <Note>();

            var mockNotesRepo = new Mock <IDeletableEntityRepository <Note> >();

            mockNotesRepo.Setup(x => x.AddAsync(It.IsAny <Note>()))
            .Callback((Note newNote) =>
            {
                newNote.Id = "newDbId";
                notesList.Add(newNote);
            });

            var notesService = new NotesService(mockNotesRepo.Object);

            var result = await notesService.CreateNoteAsync(newNote);

            Assert.Equal("newDbId", result.Id);
            Assert.Single(notesList);
        }
Ejemplo n.º 4
0
        private async Task CreateNoteCommandExecute()
        {
            var ci = CrossMultilingual.Current.CurrentCultureInfo;

            if (string.IsNullOrWhiteSpace(Description))
            {
                var descriptionEmptyMessageLocalized =
                    Resmgr.Value.GetString(ConstantsHelper.DescriptionEmptyMessage, ci);
                _alertService.ShowOkAlert(descriptionEmptyMessageLocalized, ConstantsHelper.Ok);
                return;
            }
            var noteModel = new NoteModel
            {
                // UserId = Settings.CurrentUserId,
                UserId      = "05f9947f-6e27-44fc-a7d7-16c2f9189331",
                Description = Description,
                Date        = DateTime.Now
            };
            var photosModels = Photos.ToPhotoModels();

            //foreach (var photoModel in photosModels)
            //{
            //    photoModel.Note = noteModel;
            //}
            noteModel.Photos = photosModels.ToArray();

            // await App.NoteRepository.CreateAsync(noteModel);
            // await App.NoteRepository.SaveAsync();
            var result = await NotesService.Create(noteModel);

            if (result)
            {
                MessagingCenter.Send(this, ConstantsHelper.ShouldUpdateUI);
            }
        }
Ejemplo n.º 5
0
        public async void Returns_NotFoundObjectResult404_when_NoteNotBelongsToLoggedUser()
        {
            IDatabaseContext    databaseContext     = DatabaseTestHelper.GetContext();
            MapperConfiguration mapperConfiguration = new MapperConfiguration(conf =>
            {
                conf.AddProfile(new Note_to_NoteOut());
            });
            IMapper mapper = mapperConfiguration.CreateMapper();

            INotesService notesService = new NotesService(databaseContext, mapper);

            Note note = new Note
            {
                ResourceType    = DAO.Models.Base.ResourceType.NOTE,
                Title           = "Note's title",
                Content         = "Note's content",
                OwnerID         = Guid.NewGuid().ToString(),
                CreatedDateTime = DateTime.Now
            };

            await databaseContext.Notes.AddAsync(note);

            await databaseContext.SaveChangesAsync();

            Assert.True(databaseContext.Notes.Any(_ => _.ID == note.ID));

            StatusCode <NoteOut> status = await notesService.GetByIdAndUser(note.ID, ADMIN_USERNAME);

            Assert.NotNull(status);
            Assert.Equal(StatusCodes.Status404NotFound, status.Code);
        }
Ejemplo n.º 6
0
        public async void Returns_OkObjectResult200AndNoteOut_when_NoteExistsAndBelongsToUser()
        {
            IDatabaseContext    databaseContext     = DatabaseTestHelper.GetContext();
            MapperConfiguration mapperConfiguration = new MapperConfiguration(conf =>
            {
                conf.AddProfile(new Note_to_NoteOut());
            });
            IMapper mapper = mapperConfiguration.CreateMapper();

            INotesService notesService = new NotesService(databaseContext, mapper);

            string userId = (await databaseContext.Users.FirstOrDefaultAsync(_ => _.UserName == ADMIN_USERNAME)).Id;

            Note note = new Note
            {
                ResourceType    = DAO.Models.Base.ResourceType.NOTE,
                Title           = "Note's title",
                Content         = "Note's content",
                OwnerID         = userId,
                CreatedDateTime = DateTime.Now
            };

            await databaseContext.Notes.AddAsync(note);

            await databaseContext.SaveChangesAsync();

            Assert.True(databaseContext.Notes.Any(_ => _.ID == note.ID));

            StatusCode <NoteOut> status = await notesService.GetByIdAndUser(note.ID, ADMIN_USERNAME);

            Assert.NotNull(status);
            Assert.Equal(StatusCodes.Status200OK, status.Code);
            Assert.NotNull(status.Body);
            Assert.IsType <NoteOut>(status.Body);
        }
Ejemplo n.º 7
0
        public async Task Update_Note_Successfully()
        {
            var noteId = Guid.NewGuid();

            var options = DbContextHelper.GetTestInMemoryDatabase(nameof(Update_Note_Successfully));

            using (var context = new NoteTakerContext(options, httpContextAccessor.Object))
            {
                context.Add(new Note
                {
                    Id      = noteId,
                    Title   = "Apples",
                    Content = "Oranges",
                    User    = user
                });

                context.SaveChanges();
            };

            using (var context = new NoteTakerContext(options, httpContextAccessor.Object))
            {
                var service = new NotesService(context, httpContextAccessor.Object);

                var updatedNote = await service.UpdateNoteAsync(noteId.ToString(), "New Title", "New Content");

                updatedNote.Should().NotBeNull();
                updatedNote.Title.Should().BeEquivalentTo("New Title");
                updatedNote.Content.Should().BeEquivalentTo("New Content");
            };
        }
Ejemplo n.º 8
0
        public async Task Delete_Note_Successfully()
        {
            var options = DbContextHelper.GetTestInMemoryDatabase(nameof(Delete_Note_Successfully));

            var noteToDelete = Guid.NewGuid();

            using (var context = new NoteTakerContext(options, httpContextAccessor.Object))
            {
                context.Notes.Add(new Note
                {
                    Id       = noteToDelete,
                    Title    = "Apples",
                    Content  = "Oranges",
                    Created  = DateTime.Now,
                    Modified = DateTime.Now.AddDays(-7),
                    User     = user
                });

                context.SaveChanges();
            };

            using (var context = new NoteTakerContext(options, httpContextAccessor.Object))
            {
                var service = new NotesService(context, httpContextAccessor.Object);

                await service.DeleteNoteAsync(noteToDelete.ToString());

                context.Notes.FirstOrDefault(x => x.Id == noteToDelete).Should().BeNull();
            };
        }
Ejemplo n.º 9
0
        public async void Returns_NotFoundObjectResult404_when_NoteNotExists()
        {
            IDatabaseContext    databaseContext     = DatabaseTestHelper.GetContext();
            MapperConfiguration mapperConfiguration = new MapperConfiguration(conf =>
            {
                conf.AddProfile(new Note_to_NoteOut());
                conf.AddProfile(new JsonPatchDocument_NotePatch_Mapper());
            });
            IMapper mapper = mapperConfiguration.CreateMapper();

            INotesService notesService = new NotesService(databaseContext, mapper);

            string userId = (await databaseContext.Users
                             .FirstOrDefaultAsync(_ => _.UserName == ADMIN_USERNAME))?
                            .Id;

            string newContent = "Changed content";

            JsonPatchDocument <NotePatch> jsonPatchDocument = new JsonPatchDocument <NotePatch>();

            jsonPatchDocument.Add(_ => _.Content, newContent);

            StatusCode <NoteOut> status = await notesService.PatchByIdAndNotePatchAndUser(Guid.NewGuid(), jsonPatchDocument, ADMIN_USERNAME);

            Assert.NotNull(status);
            Assert.Equal(StatusCodes.Status404NotFound, status.Code);
        }
Ejemplo n.º 10
0
        public async Task AddNote(string note)
        {
            Note newNote = NotesService.Add(note);

            // All connected clients will receive this call
            await Clients.All.BroadcastNewNote(newNote);
        }
 public Note()
 {
     BindingContext = this;
     ns             = new NotesService(App.token, Navigation);
     //Navigation.PushAsync(new LoginPage());
     InitializeComponent();
 }
Ejemplo n.º 12
0
        public void PublishMessageIfNoteIsAdded()
        {
            var sut = new NotesService(storageMoq.Object, eventsMoq.Object);

            sut.AddNote(new Note(), 2);
            eventsMoq.Verify(f => f.NotifyAdded(It.IsAny <Note>(), 2), Times.AtLeast(1));
        }
        public void Put()
        {
            using (IDataContextAsync context = new LandmarkRemarkContext())
                using (IUnitOfWorkAsync unitOfWork = new UnitOfWork(context))
                {
                    IRepositoryAsync <Note> repository   = new Repository <Note>(context, unitOfWork);
                    INotesService           notesService = new NotesService(repository);
                    NotesController         controller   = new NotesController(notesService, unitOfWork);

                    var response = controller.PutNote(7, new Note
                    {
                        Notes   = "Notes tested",
                        Address = "300 Eu Tong Sen St, Singapore 059816",
                        Date    = DateTime.Now,
                        Lat     = 1.279366441843M,
                        Lng     = 103.839335128002M,
                        User    = "******",
                        NoteId  = 7
                    });


                    var data = (response as dynamic).Content;
                    Assert.AreEqual(data.success, true);
                }
        }
 public NoteHistoryControl()
 {
     InitializeComponent();
     _notesService = new NotesService();
     _noteHistory  = new ObservableCollection <NoteVersion>();
     versionComboBox.ItemsSource = _noteHistory;
 }
Ejemplo n.º 15
0
        public IActionResult PostMethod([FromBody] NewNoteRequestDto model)
        {
            if (ModelState.IsValid)
            {
                var dateTimeOffset = NotesService.GetDateTimeOffsetValue(model.Lifetime);

                var item = new NoteRepositoryItem
                {
                    Id             = NotesService.GenerateId(),
                    Title          = model.Title,
                    Text           = model.NoteText,
                    CreateDateTime = DateTime.UtcNow,
                    Lifetime       = dateTimeOffset
                };

                try
                {
                    _notesService.Add(item);
                }
                catch (Exception exception)
                {
                    // todo: log exception
                    return(BadRequest("Can't add the note. Server error."));
                }

                var result = item.ToDto();

                return(Ok(result));
            }

            return(BadRequest(ModelState));
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TodoistClient" /> class.
        /// </summary>
        /// <param name="token">The token.</param>
        /// <param name="restClient">The rest client.</param>
        /// <exception cref="System.ArgumentException">Value cannot be null or empty - token</exception>
        public TodoistClient(string token, ITodoistRestClient restClient)
        {
            if (string.IsNullOrEmpty(token))
            {
                throw new ArgumentException("Value cannot be null or empty.", nameof(token));
            }

            _token      = token;
            _restClient = restClient;

            Projects      = new ProjectsService(this);
            Templates     = new TemplateService(this);
            Items         = new ItemsService(this);
            Labels        = new LabelsService(this);
            Notes         = new NotesService(this);
            Uploads       = new UploadService(this);
            Filters       = new FiltersService(this);
            Activity      = new ActivityService(this);
            Notifications = new NotificationsService(this);
            Backups       = new BackupService(this);
            Reminders     = new RemindersService(this);
            Users         = new UsersService(this);
            Sharing       = new SharingService(this);
            Emails        = new EmailService(this);
            Sections      = new SectionService(this);
        }
Ejemplo n.º 17
0
        public async Task CreateCaseTests()
        {
            AutoMapperConfig.RegisterMappings(typeof(CreateCaseInputViewModel).GetTypeInfo().Assembly);

            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "TestCreateCaseDb")
                          .Options;

            using var dbContext = new ApplicationDbContext(options);

            dbContext.Cases.AddRange(
                new Case()
            {
                CaseNumber = "1",
                AttorneyId = "1",
                ClientId   = "1",
                JudgeId    = 1,
                TrusteeId  = 1,
                DateFiled  = DateTime.UtcNow,
            });

            dbContext.SaveChanges();

            using var casesRepository = new EfDeletableEntityRepository <Case>(dbContext);
            using var notesRepository = new EfDeletableEntityRepository <Note>(dbContext);

            var notesService = new NotesService(notesRepository);
            var casesService = new CasesService(casesRepository, notesService);

            var workingInput = new CreateCaseInputViewModel()
            {
                CaseNumber = "2",
                AttorneyId = "2",
                JudgeId    = "2",
                TrusteeId  = "2",
                DateFiled  = DateTime.UtcNow,
            };

            var duplicateCaseNumberInput = new CreateCaseInputViewModel()
            {
                CaseNumber = "1",
                AttorneyId = "2",
                JudgeId    = "2",
                TrusteeId  = "2",
                DateFiled  = DateTime.UtcNow,
            };

            var caseId = await casesService.CreateCaseAsync("newClient", workingInput);

            Assert.True(caseId is string);

            await Assert.ThrowsAsync <ArgumentException>(
                async() =>
            {
                await casesService.CreateCaseAsync("newClient", duplicateCaseNumberInput);
            });

            Assert.Equal(2, casesRepository.AllAsNoTracking().Count());
        }
Ejemplo n.º 18
0
        public void NotPublishMessageIfDeleteNoteIsFailed()
        {
            var sut = new NotesService(storageMoq.Object, eventsMoq.Object);

            storageMoq.Setup(ev => ev.DeleteNote(It.IsAny <Guid>())).Returns(false);
            sut.DeleteNote(new Guid(), 2);
            eventsMoq.Verify(f => f.NotifyDeleted(It.IsAny <Guid>(), 2), Times.Never);
        }
Ejemplo n.º 19
0
        public void PublishMessageIfNoteIsDeleted()
        {
            var sut = new NotesService(storageMoq.Object, eventsMoq.Object);

            storageMoq.Setup(ev => ev.DeleteNote(It.IsAny <Guid>())).Returns(true);
            sut.DeleteNote(new Guid(), 2);
            eventsMoq.Verify(f => f.NotifyDeleted(It.IsAny <Guid>(), 2), Times.AtLeast(1));
        }
Ejemplo n.º 20
0
        public void IfNoteIsNullThrowArgumentNullException()
        {
            var noteService = new NotesService(new Mock <INotesStorage>().Object, new Mock <INoteEvents>().Object);

            void Action() => noteService.AddNote(null, It.IsAny <int>());

            Assert.Throws <ArgumentNullException>(Action);
        }
Ejemplo n.º 21
0
        public void AddEvent_Should_Return_Null_Exception_If_Note_Null()
        {
            var notesStorage = Substitute.For <INotesStorage>();
            var noteEvents   = Substitute.For <INoteEvents>();
            var sut          = new NotesService(notesStorage, noteEvents);

            Assert.Throws <ArgumentNullException>(() => sut.AddNote(null, 1));
        }
Ejemplo n.º 22
0
        public async void OnDeleteNote(object sender, EventArgs e)
        {
            NoteNameEntry.Text = string.Empty;
            NoteTextEntry.Text = string.Empty;
            await NotesService.DeleteNote(NoteModel);

            await Navigation.PopAsync();
        }
Ejemplo n.º 23
0
 public async Task RemoveNote(int noteId)
 {
     if (NotesService.Remove(noteId))
     {
         // All connected clients will receive this call
         await Clients.All.BroadcastRemoveNote(noteId);
     }
 }
Ejemplo n.º 24
0
        private async Task RefreshCommandExecute()
        {
            IsRefreshing = true;
            var noteModels = await NotesService.GetNotes();

            Notes        = new ObservableCollection <NoteModel>(noteModels);
            IsRefreshing = false;
        }
Ejemplo n.º 25
0
        public void AddNote_If_Arguments_IsCorrect_NoteEvent_MustCall_NotifyAdded()
        {
            var service = new NotesService(_storageMoq.Object, _eventMoq.Object);

            service.AddNote(_testNote, _testUserId);

            _eventMoq.Verify(x => x.NotifyAdded(_testNote, _testUserId), Times.Once);
        }
Ejemplo n.º 26
0
 public HomeController(NotesService notesService, FilesService filesService, TagsService tagsService,
                       IAuthorizationService authorizationService, ILogger <HomeController> logger)
 {
     _notesService         = notesService;
     _filesService         = filesService;
     _tagsService          = tagsService;
     _authorizationService = authorizationService;
     _logger = logger;
 }
Ejemplo n.º 27
0
 public NotesController(NotesService notesService, TagsService tagsService,
                        IAuthorizationService authorizationService, IMapper mapper, ILogger <NotesController> logger)
 {
     _notesService         = notesService;
     _tagsService          = tagsService;
     _authorizationService = authorizationService;
     _mapper = mapper;
     _logger = logger;
 }
Ejemplo n.º 28
0
        public void GetAllCasesForClientTests()
        {
            var options = new DbContextOptionsBuilder <ApplicationDbContext>()
                          .UseInMemoryDatabase(databaseName: "TestGetAllCasesForClientDb")
                          .Options;

            using var dbContext = new ApplicationDbContext(options);

            dbContext.Cases.AddRange(
                new Case()
            {
                CaseNumber = "1",
                Attorney   = new ApplicationUser()
                {
                    FirstName = "niki",
                    LastName  = "mitrev",
                },
                ClientId  = "1",
                Judge     = new Judge(),
                Trustee   = new Trustee(),
                DateFiled = DateTime.UtcNow,
            },
                new Case()
            {
                CaseNumber = "3",
                Attorney   = new ApplicationUser()
                {
                    FirstName = "niki",
                    LastName  = "mitrev",
                },
                ClientId  = "1",
                Judge     = new Judge(),
                Trustee   = new Trustee(),
                DateFiled = DateTime.UtcNow.AddDays(1),
            });

            dbContext.SaveChanges();

            using var casesRepository = new EfDeletableEntityRepository <Case>(dbContext);
            using var notesRepository = new EfDeletableEntityRepository <Note>(dbContext);

            var notesService = new NotesService(notesRepository);
            var casesService = new CasesService(casesRepository, notesService);

            AllClientCasesViewModel result = casesService.GetAllCasesForClient("1", "Gosho");

            var countOfCases = result.Cases.Count();

            var clientName = result.ClientName;

            var caseOnTop = result.Cases.First();

            Assert.Equal(2, countOfCases);
            Assert.Equal("Gosho", clientName);
            Assert.Equal("3", caseOnTop.CaseNumber);
        }
Ejemplo n.º 29
0
        public MainWindow()
        {
            InitializeComponent();

            _notesService = new NotesService();

            CurrentNotebook = _notesService.GetNotebook("1");
            //notesList.DataContext = CurrentNotebook.Notes;
            notebookEditControl.LoadNotebook(CurrentNotebook);
        }
Ejemplo n.º 30
0
        public void DeleteNote_If_NotesStorage_DontDeletedNote_NoteEvent_Dont_Call_NotifyDeleted()
        {
            _storageMoq.Setup(x => x.DeleteNote(_testNote.Id)).Returns(false);

            var service = new NotesService(_storageMoq.Object, _eventMoq.Object);

            service.DeleteNote(_testNote.Id, _testUserId);

            _eventMoq.Verify(x => x.NotifyDeleted(_testNote.Id, _testUserId), Times.Never);
        }