예제 #1
0
            public void GivenNullCard_ThenThrowsArgumentNullException()
            {
                // arrange
                var repo = new JsonCardListRepository(new DirectoryInfo(@"."), new DirectoryInfo(@"."));

                // act
                repo.Save <Card>(null);

                // assert
                Assert.Fail("ArgumentNullException should have been thrown.");
            }
예제 #2
0
            public void Given_ThenReturnsQueryable()
            {
                // arrange
                var repo = new JsonCardListRepository(new DirectoryInfo(@"."), new DirectoryInfo(@"."));

                // act
                var result = repo.GetAll <Card>();

                // assert
                Assert.IsNotNull(result);
            }
예제 #3
0
            public void GivenCardIsNotPresent_ThenReturnsNull()
            {
                // arrange
                var id   = Guid.NewGuid();
                var repo = new JsonCardListRepository(new DirectoryInfo(@"."), new DirectoryInfo(@"."));

                // act
                var result = repo.GetById <Card>(id);

                // assert
                Assert.IsNull(result);
            }
예제 #4
0
            public void GivenCardNotFound_ThenThrowsInvalidOperationException()
            {
                // arrange
                var repo = new JsonCardListRepository(new DirectoryInfo(@"."), new DirectoryInfo(@"."));
                var card = new Card {
                    DbId = Guid.NewGuid()
                };

                // act
                repo.Delete(card);

                // assert
                Assert.Fail("InvalidOperationException should have been thrown.");
            }
예제 #5
0
            public void GivenCardFound_ThenCardRemoved()
            {
                // arrange
                var repo = new JsonCardListRepository(new DirectoryInfo(@"."), new DirectoryInfo(@"."));
                var card = new Card {
                    DbId = Guid.NewGuid()
                };

                repo.Data[typeof(Card)].Add(card);

                // act
                repo.Delete(card);

                // assert
                Assert.AreEqual(0, repo.Data[typeof(Card)].Count);
                Assert.IsFalse(repo.Data[typeof(Card)].Cast <Card>().Any(x => x.DbId == card.DbId));
            }
예제 #6
0
            public void GivenCardIsPresent_ThenReturnsCard()
            {
                // arrange
                var id   = Guid.NewGuid();
                var repo = new JsonCardListRepository(new DirectoryInfo(@"."), new DirectoryInfo(@"."));
                var card = new Card {
                    DbId = id
                };

                repo.Data[typeof(Card)].Add(card);

                // act
                var result = repo.GetById <Card>(id);

                // assert
                Assert.IsNotNull(result);
                Assert.AreEqual(id, result.DbId);
            }
예제 #7
0
            public void GivenValidCardToInsert_ThenSave()
            {
                // arrange
                var repo         = new JsonCardListRepository(new DirectoryInfo(@"."), new DirectoryInfo(@"."));
                var cardToInsert = new Card {
                    Name = "Test Card"
                };

                // act
                var result = repo.Save(cardToInsert);

                // assert
                Assert.AreEqual(1, repo.Data[typeof(Card)].Count);
                Assert.AreNotEqual(Guid.Empty, result);
                Assert.AreEqual(result, cardToInsert.DbId);
                Assert.AreEqual(result, repo.Data[typeof(Card)].Cast <Card>().ToList()[0].DbId);
                Assert.AreEqual(cardToInsert.Name, repo.Data[typeof(Card)].Cast <Card>().ToList()[0].Name);
            }
예제 #8
0
            public void GivenValidCardToUpdate_ThenSave()
            {
                // arrange
                var id   = Guid.NewGuid();
                var repo = new JsonCardListRepository(new DirectoryInfo(@"."), new DirectoryInfo(@"."));

                repo.Data[typeof(Card)].Add(new Card {
                    DbId = id
                });
                var cardToUpdate = new Card {
                    DbId = id, Name = "Test Card"
                };

                // act
                var result = repo.Save(cardToUpdate);

                // assert
                Assert.AreEqual(1, repo.Data[typeof(Card)].Count);
                Assert.AreEqual(id, result);
                Assert.AreEqual(id, cardToUpdate.DbId);
                Assert.AreEqual(id, repo.Data[typeof(Card)].Cast <Card>().ToList()[0].DbId);
                Assert.AreEqual(cardToUpdate.Name, repo.Data[typeof(Card)].Cast <Card>().ToList()[0].Name);
            }