Exemple #1
0
        public async Task TestClientCrudOperationsAsync()
        {
            var note1 = await _httpClient.CreateNoteAsync(null, NoteTestModelV1.GenerateRandomNote());

            var note2 = await _httpClient.CreateNoteAsync(null, NoteTestModelV1.GenerateRandomNote());

            //dynamic projectionResult = await _httpClient.GetNotesAsync(null, null, null);
            //Assert.Equal(note1.Title, projectionResult.Data[0].Title);
            //Assert.Equal(note2.Title, projectionResult.Data[1].Title);

            var page = await _httpClient.GetNotesAsync(null, null, null);

            Assert.Equal(2, page.Data.Count);

            await _httpClient.DeleteNoteByIdAsync(null, note1.Id);

            //projectionResult = await _httpClient.GetNoteByIdAsync(null, note2.Id);
            //Assert.Equal(note2.Id, projectionResult.Id);

            var result = await _httpClient.GetNoteByIdAsync(null, note2.Id);

            Assert.NotNull(result);

            await _httpClient.DeleteNoteByIdAsync(null, note2.Id);

            page = await _httpClient.GetNotesAsync(null, null, null);

            Assert.Empty(page.Data);
        }
        public async void It_Should_Get_Note_Async()
        {
            var note = NoteTestModelV1.GenerateRandomNote();

            _moqPersistence.Setup(p => p.GetNoteByIdAsync(null, note.Id)).ReturnsAsync(note);

            var result = await _controller.GetNoteByIdAsync(null, note.Id);

            Assert.Equal(note.Id, result.Id);
        }
        public async Task TestGetNoteById()
        {
            // arrange
            var note = await _persistence.CreateNoteAsync(null, NoteTestModelV1.GenerateRandomNote());

            // act
            var result = await _persistence.GetNoteByIdAsync(null, note.Id);

            // assert
            NoteTestModelV1.AssertEqual(note, result);
        }
        public async Task TestUpdateNote()
        {
            // arrange
            var note = await _persistence.CreateNoteAsync(null, NoteTestModelV1.GenerateRandomNote());

            // act
            note.Title       = "T";
            note.Description = "holiday";

            var result = await _persistence.UpdateNoteAsync(null, note);

            // assert
            NoteTestModelV1.AssertEqual(note, result);
        }
        public async void It_Should_Get_Notes_Async()
        {
            var notes = new DataPage <NoteV1>
            {
                Data = new List <NoteV1> {
                    NoteTestModelV1.GenerateRandomNote(), NoteTestModelV1.GenerateRandomNote(), NoteTestModelV1.GenerateRandomNote()
                },
                Total = 3
            };
            var filter = new FilterParams();
            var paging = new PagingParams();

            _moqPersistence.Setup(p => p.GetNotesAsync(null, filter, paging)).ReturnsAsync(notes);

            var result = await _controller.GetNotesAsync(null, filter, paging);

            Assert.Equal(notes.Total, result.Total);
        }
Exemple #6
0
        public async Task IT_Should_Test_Crud_Operations()
        {
            var expectedNote1 = NoteTestModelV1.GenerateRandomNote();
            var Note1         = await Invoke <NoteV1>("create_note", new { Note = expectedNote1 });

            NoteTestModelV1.AssertEqual(expectedNote1, Note1);

            var expectedNote2 = NoteTestModelV1.GenerateRandomNote();
            var Note2         = await Invoke <NoteV1>("create_note", new { Note = expectedNote2 });

            NoteTestModelV1.AssertEqual(expectedNote2, Note2);

            var page = await Invoke <DataPage <NoteV1> >("get_notes", new { });

            Assert.NotNull(page);
            Assert.Equal(2, page.Data.Count);

            Note1.Title       = "Updated Type";
            Note1.Description = "Updated Code";

            var Note = await Invoke <NoteV1>("update_note", new { Note = Note1 });

            NoteTestModelV1.AssertEqual(Note1, Note);

            Note = await Invoke <NoteV1>("delete_note_by_id", new { id = Note1.Id });

            Assert.NotNull(Note);
            Assert.Equal(Note1.Id, Note.Id);

            Note = await Invoke <NoteV1>("delete_note_by_id", new { id = Note1.Id });

            Assert.Null(Note);

            Note = await Invoke <NoteV1>("delete_note_by_id", new { id = Note2.Id });

            Assert.NotNull(Note);
            Assert.Equal(Note2.Id, Note.Id);

            Note = await Invoke <NoteV1>("get_note_by_id", new { id = Note2.Id });

            Assert.Null(Note);
        }
        public async Task TestGetNoteByIdsFilter()
        {
            // arrange
            var note1 = await _persistence.CreateNoteAsync(null, NoteTestModelV1.GenerateRandomNote());

            var note2 = await _persistence.CreateNoteAsync(null, NoteTestModelV1.GenerateRandomNote());

            var note3 = await _persistence.CreateNoteAsync(null, NoteTestModelV1.GenerateRandomNote());

            var filter = FilterParams.FromTuples(
                "ids", $"{note2.Id}"
                );

            // act
            var result = await _persistence.GetNotesAsync(null, filter, null);

            // assert
            Assert.NotNull(result);
            Assert.Single(result.Data);
            NoteTestModelV1.AssertEqual(note2, result.Data[0]);
        }
        public async Task TestGetNotesByComplexFilter()
        {
            // arrange
            var note1 = await _persistence.CreateNoteAsync(null, NoteTestModelV1.GenerateRandomNote());

            var note2 = await _persistence.CreateNoteAsync(null, NoteTestModelV1.GenerateRandomNote());

            var note3 = await _persistence.CreateNoteAsync(null, NoteTestModelV1.GenerateRandomNote());

            var filter = FilterParams.FromTuples(
                "ids", $"{note2.Id},{note1.Id}",
                "Ids", $"{note1.Id}",
                "type", note1.Title,
                "code", note1.Description
                );

            // act
            var result = await _persistence.GetNotesAsync(null, filter, null);

            // assert
            Assert.NotNull(result);
            Assert.Single(result.Data);
            NoteTestModelV1.AssertEqual(note1, result.Data[0]);
        }