Beispiel #1
0
        public void AddNullItems_ThrowsBadRequestException()
        {
            var repo = new Mock <IResourceRepository>();

            var domain = new ResourceDomain(repo.Object);

            Should.Throw <BadRequestException>(() => domain.UpdateList(null));
        }
Beispiel #2
0
        public void AddUpdateAndDeleteItems_ItemsAreAddedUpdatedAndDeleted()
        {
            const string partition = "part1";
            var          dbList    = new List <Resource>();
            var          res1      = new Resource {
                Partition = partition, Key = "a", Value = "foo1"
            };
            var res2 = new Resource {
                Partition = partition, Key = "b", Value = "foo2"
            };
            var res3 = new Resource {
                Partition = partition, Key = "c", Value = "foo3"
            };

            dbList.Add(res1);
            dbList.Add(res2);
            dbList.Add(res3);

            var repo = new Mock <IResourceRepository>();

            repo.Setup(x => x.List(partition)).Returns(dbList.AsEnumerable());
            repo.Setup(x => x.Get(res1.Key, res1.Partition)).Returns(res1);
            repo.Setup(x => x.Get(res2.Key, res2.Partition)).Returns(res2);
            repo.Setup(x => x.Get(res3.Key, res3.Partition)).Returns(res3);

            var domain = new ResourceDomain(repo.Object);

            var list = new List <ResourceDto>
            {
                new ResourceDto {
                    Partition = partition, Key = "a", Value = "bar1"
                },
                new ResourceDto {
                    Partition = partition, Key = "b", Value = "bar2"
                },
                new ResourceDto {
                    Partition = partition, Key = "d", Value = "bar3"
                },
                new ResourceDto {
                    Partition = partition, Key = "e", Value = "bar4"
                },
            };

            domain.UpdateList(list);

            repo.Verify(x => x.Create(It.Is <Resource>(y =>
                                                       y.Key == "d" && y.Partition == partition && y.Value == "bar3" ||
                                                       y.Key == "e" && y.Partition == partition && y.Value == "bar4")), Times.Exactly(2));
            repo.Verify(x => x.Update(It.Is <Resource>(y =>
                                                       y.Key == "a" && y.Partition == partition && y.Value == "bar1" ||
                                                       y.Key == "b" && y.Partition == partition && y.Value == "bar2")), Times.Exactly(2));
            repo.Verify(x => x.Delete(It.Is <Resource>(y =>
                                                       y.Key == "c" && y.Partition == partition)), Times.Exactly(1));
        }
Beispiel #3
0
        public void AddItemsOfDifferentPartitions_ThrowsBadRequestException()
        {
            var repo = new Mock <IResourceRepository>();

            var domain = new ResourceDomain(repo.Object);

            var list = new List <ResourceDto>
            {
                new ResourceDto {
                    Partition = "X", Key = "A", Value = "foo"
                },
                new ResourceDto {
                    Partition = "Y", Key = "A", Value = "bar"
                }
            };

            Should.Throw <BadRequestException>(() => domain.UpdateList(list));
        }
Beispiel #4
0
        public void AddANullItem_ThrowsBadRequestException()
        {
            const string partition = "part1";

            var repo = new Mock <IResourceRepository>();

            var domain = new ResourceDomain(repo.Object);

            var list = new List <ResourceDto>
            {
                new ResourceDto {
                    Partition = partition, Key = "a", Value = "bar1"
                },
                new ResourceDto {
                    Partition = partition, Key = "b", Value = "bar2"
                },
                null,
                new ResourceDto {
                    Partition = partition, Key = "e", Value = "bar4"
                },
            };

            Should.Throw <BadRequestException>(() => domain.UpdateList(list));
        }