Exemple #1
0
        public async Task NoteControllerGetExistsTrue()
        {
            var model  = NoteData.GetFirst();
            var master = UserData.GetFirst();
            var data   = new NoteApiDataHandler()
            {
                ResultNotable = master
            };

            data.Result.Setup(m => m.Execute(It.IsAny <NotesByRefId>())).Returns(model);

            var controller = new NoteController(data, Logic)
            {
                CurrentUser = StandardUser
            };
            var result = await controller.Get(NoteData.FirstId) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();
            result.Value.Should().BeOfType <NotableViewModel>();

            var check = result.Value as NotableViewModel;

            check.Should().NotBeNull();
            check.Notable.Should().NotBeNull();
            check.Message.Should().BeNull();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <NotesByRefId>()), Times.Once());
        }
Exemple #2
0
        public async Task NoteControllerPostDelete()
        {
            var data  = new NoteApiDataHandler();
            var model = NoteData.GetFirst();

            data.Result.Setup(m => m.Execute(It.IsAny <NotesByRefId>())).Returns(model);
            data.Result.Setup(m => m.Execute(It.IsAny <Persist <Notes> >())).Returns(model);

            var controller = new NoteController(data, Logic)
            {
                CurrentUser = StandardUser
            };
            var result = await controller.Delete(NoteData.FirstId, "0") as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();
            result.Value.Should().NotBeNull();

            var check = result.Value as NotableViewModel;

            check.Notes.Name.Should().Be(model.Name);

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeTrue();
            data.Result.Verify(s => s.Execute(It.IsAny <NotesByRefId>()), Times.Once);
            data.Result.Verify(s => s.Execute(It.IsAny <Persist <Notes> >()), Times.Once());
        }
Exemple #3
0
        public async Task NoteByRefIdDataTest()
        {
            using var store   = GetDocumentStore();
            using var session = store.OpenAsyncSession();
            var loader = new NotesByRefId {
                Session = session, Id = UserData.FirstId
            };
            await loader.Execute();

            loader.Result.Should().NotBeNull();
            loader.Result.Id.Should().Be(NoteData.FirstId);
            Assert.That(loader.Result, Is.DeepEqualTo(NoteData.GetFirst()));
        }
Exemple #4
0
        protected override void SetupDatabase(IDocumentStore store)
        {
            store.ExecuteIndex(new NoteIndex());
            store.ExecuteIndex(new NotableIndex());

            using (var session = store.OpenSession())
            {
                session.Store(NoteData.GetFirst());
                session.SaveChanges();
            }

            WaitForIndexing(store);
        }
Exemple #5
0
        public void NotesMasterTest()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Notes, NotesMaster>();
                cfg.CreateMap <NotesMaster, Notes>();
            });

            var mapper   = new Mapper(config);
            var master   = mapper.Map <NotesMaster>(NoteData.GetFirst());
            var document = mapper.Map <Notes>(master);

            master.Should().NotBeNull();
            document.Should().NotBeNull();

            master.Authors = new List <string>();
            master.Authors.Count().Should().Be(0);
        }
Exemple #6
0
        public async Task NoteControllerGetNoNotable()
        {
            var data   = new NoteApiDataHandler();
            var master = NoteData.GetFirst();

            data.Result.Setup(m => m.Execute(It.IsAny <NotesByRefId>())).Returns(null);

            var controller = new NoteController(data, Logic)
            {
                CurrentUser = StandardUser
            };
            var result = await controller.Get(NoteData.FirstId) as NotFoundResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <NotFoundResult>();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeFalse();
            data.Result.Verify(s => s.Execute(It.IsAny <NotesByRefId>()), Times.Once());
        }
Exemple #7
0
        public async Task NoteControllerPostAddExisting()
        {
            var data  = new NoteApiDataHandler();
            var model = NoteData.GetFirst();

            model.History.Add(new Note()
            {
                Counter = 1
            });

            var viewModel = new NoteViewModel {
                Id = NoteData.FirstId, Text = "New Note", Counter = 1, IsPrivate = false, ForceNotify = false
            };

            data.Result.Setup(m => m.Execute(It.IsAny <NotesByRefId>())).Returns(model);
            data.Result.Setup(m => m.Execute(It.IsAny <Persist <Notes> >())).Returns(model);

            var controller = new NoteController(data, Logic)
            {
                CurrentUser = StandardUser
            };
            var result = await controller.Post(viewModel) as OkObjectResult;

            result.Should().NotBeNull();
            result.Should().BeOfType <OkObjectResult>();
            result.Value.Should().NotBeNull();

            var check = result.Value as NotableViewModel;

            check.Notes.Name.Should().Be(model.Name);
            check.Notes.History.Count().Should().Be(2);

            viewModel.ForceNotify.Should().BeFalse();
            viewModel.IsPrivate.Should().BeFalse();

            data.HasExecuted.Should().BeTrue();
            data.HasCommitted.Should().BeTrue();
            data.Result.Verify(s => s.Execute(It.IsAny <NotesByRefId>()), Times.Once);
            data.Result.Verify(s => s.Execute(It.IsAny <Persist <Notes> >()), Times.Once());
        }