public void EFRepository_AddNote_ValidCall()
        {
            List <Note> listOfNotes = CreateTestData.GetListOfNotes();
            var         mockSet     = new Mock <DbSet <Note> >()
                                      .SetupData(listOfNotes, o =>
            {
                return(listOfNotes.Single(x => x.Note_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var expected = CreateTestData.GetSampleNote();
                var id       = Guid.Parse("b346eee6-eba7-4ea7-be2e-911bb9034233");
                expected.Note_id = id;

                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <Note>()).Returns(mockSet.Object);

                //Act
                INotesRepository toTest = mockContext.Create <NotesRepository>();
                toTest.Add(expected);
                var actual = toTest.Get(id);

                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <Note>();
                expected.Should().BeOfType <Note>();
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void EFRepository__GetNote_ValidCall()
        {
            //Arrange
            List <Note> listOfNotes = CreateTestData.GetListOfNotes();
            var         mockSet     = new Mock <DbSet <Note> >()
                                      .SetupData(listOfNotes, o =>
            {
                return(listOfNotes.Single(x => x.Note_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var expected = CreateTestData.GetSampleNote();
                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <Note>()).Returns(mockSet.Object);

                //Act
                INotesRepository toTest = mockContext.Create <NotesRepository>();
                var actual = toTest.Get(expected.Note_id);

                //Assert
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <Note>();
                expected.Should().BeOfType <Note>();
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void EFRepository__DeleteNote_ValidCall()
        {
            //Arrange
            List <Note> listOfNotes = CreateTestData.GetListOfNotes();
            var         mockSet     = new Mock <DbSet <Note> >()
                                      .SetupData(listOfNotes, o =>
            {
                return(listOfNotes.Single(x => x.Note_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var ToBeDeleted = CreateTestData.GetSampleNote();

                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <Note>()).Returns(mockSet.Object);

                //Act
                INotesRepository toTest = mockContext.Create <NotesRepository>();
                toTest.Remove(ToBeDeleted.Note_id);

                //Assert
                listOfNotes.Should().NotBeEmpty();
                listOfNotes.Should().NotContain(ToBeDeleted);
                listOfNotes.Should().BeOfType <List <Note> >();
            }
        }
Пример #4
0
        public void CMBuilder_buildNoteCMsForCharacter_ValidCall()
        {
            List <Note> notes   = CreateTestData.GetListOfNotes();
            var         mockSet = new Mock <DbSet <Note> >()
                                  .SetupData(notes, o =>
            {
                return(notes.Single(x => x.Character_id.CompareTo(o.First()) == 0));
            });
            Guid          Grog_id  = Guid.Parse("11111111-2222-3333-4444-555555555555");
            List <NoteCM> expected = new List <NoteCM>();


            Guid   Spelling_id  = Guid.Parse("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee");
            Note   spellingNote = notes.Find(x => x.Note_id == Spelling_id);
            NoteCM spellingCM   = CharacterMapper.mapNoteToNoteCM(spellingNote);

            spellingCM.Index = 0;
            expected.Add(spellingCM);

            Guid   GreatAxe_id  = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4");
            Note   GreatAxeNote = notes.Find(x => x.Note_id == GreatAxe_id);
            NoteCM greatAxeCM   = CharacterMapper.mapNoteToNoteCM(GreatAxeNote);

            greatAxeCM.Index = 1;
            expected.Add(greatAxeCM);

            using (var mockContext = AutoMock.GetLoose())
            {
                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <Note>()).Returns(mockSet.Object);
                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Notes).Returns(mockSet.Object);

                IUnitOfWork     uow    = UoW_Factory.getUnitofWork(mockContext);
                IBaseUserAccess access = UserAccessFactory.getBaseUserAccess(uow);

                //Act
                ICharacterCMBuilder toTest = ProcessorFactory.GetCharacterCMBuilder(access);
                var actual = toTest.buildNoteCMsFOrCharacter(Grog_id);

                //Assert
                actual.Should().BeEquivalentTo(expected);
            }
        }
        public void EFRepository_GetNotesOwnedByCharacter_ValidCall()
        {
            //Arrange
            List <Note> listOfNotes = CreateTestData.GetListOfNotes();
            var         mockSet     = new Mock <DbSet <Note> >()
                                      .SetupData(listOfNotes, o =>
            {
                return(listOfNotes.Single(x => x.Note_id.CompareTo(o.First()) == 0));
            });

            using (var mockContext = AutoMock.GetLoose())
            {
                var expected = new List <Note>();
                expected.Add(CreateTestData.GetSampleNote());
                var GreatAxe = new Note()
                {
                    Note_id      = Guid.Parse("361bd911-0702-437f-ab59-a29da0f9fba4"),
                    Character_id = Guid.Parse("11111111-2222-3333-4444-555555555555"),
                    Name         = "How To Use a Great Axe Ft. Grog Strongjaw",
                    Contents     = "Lorem Ipsum"
                };

                expected.Add(GreatAxe);

                //1. When the
                mockContext.Mock <CharacterContext>()
                .Setup(x => x.Set <Note>()).Returns(mockSet.Object);

                //Act
                INotesRepository toTest = mockContext.Create <NotesRepository>();
                var actual = toTest.GetNotesOwnedBy(Guid.Parse("11111111-2222-3333-4444-555555555555"));

                actual.Should().NotBeEmpty();
                expected.Should().NotBeEmpty();
                actual.Should().NotBeNull();
                expected.Should().NotBeNull();
                actual.Should().BeOfType <List <Note> >();
                expected.Should().BeOfType <List <Note> >();
                actual.Should().BeEquivalentTo(expected);
            }
        }