public LoadRequest(ResourceType type, IKeyed holder, AttachmentKey key, ResourceDomain domain, IResult result)
 {
     Type    = type;
     _holder = new WeakReference <IKeyed>(holder);
     Key     = key;
     Domain  = domain;
     Result  = result;
 }
Exemple #2
0
        public void AddNullItems_ThrowsBadRequestException()
        {
            var repo = new Mock <IResourceRepository>();

            var domain = new ResourceDomain(repo.Object);

            Should.Throw <BadRequestException>(() => domain.UpdateList(null));
        }
Exemple #3
0
        public void ListItemsNotFound_ThrowsNotFoundException()
        {
            var repo = new Mock <IResourceRepository>();

            repo.Setup(x => x.List("part2")).Returns(new List <Resource>());
            var domain = new ResourceDomain(repo.Object);

            Should.Throw <NotFoundException>(() => domain.List("part2"));
        }
        /// <summary>
        /// Starts 
        /// </summary>
        public static void Startup(IntPtr _unmanagedModule)
        {
            // Get and save the resource domain of the mod, needed for loading resources.
            Mod = Module.FromHandle(_unmanagedModule);
            ModDomain = Mod.ResourceDomain;

            // Create the world. Multiple worlds could be created here, but we only want one.
            // Use the UpvoidMinerWorldGenerator, which will create a simple terrain with some vegetation.
            Universe.CreateWorld("UpvoidMinerWorld", new UpvoidMinerWorldGenerator());
        }
Exemple #5
0
        public void UpdateWithMissingDto_NotFoundException()
        {
            var repo = new Mock <IResourceRepository>();

            repo.Setup(x => x.Get("foo", "foo")).Returns((Resource)null);
            var domain = new ResourceDomain(repo.Object);

            Should.Throw <NotFoundException>(() => domain.Update(new ResourceDto {
                Key = "foo", Partition = "foo"
            }));
        }
Exemple #6
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));
        }
Exemple #7
0
        public void CreateWithNewDto_DtoIsMapped()
        {
            var repo = new Mock <IResourceRepository>();

            var domain = new ResourceDomain(repo.Object);

            domain.Create(new ResourceDto {
                Key = "foo1", Partition = "foo1", Value = "bar1"
            });

            repo.Verify(x => x.Create(It.Is <Resource>(y => y.Key == "foo1" && y.Partition == "foo1" && y.Value == "bar1")));
        }
Exemple #8
0
        /// <summary>
        /// Serializes this instance of <see cref="UserStatusResourceResourceUsageSummary" /> into a <see cref="Carbon.Json.JsonNode"
        /// />.
        /// </summary>
        /// <param name="container">The <see cref="Carbon.Json.JsonObject"/> container to serialize this object into. If the caller
        /// passes in <c>null</c>, a new instance will be created and returned to the caller.</param>
        /// <param name="serializationMode">Allows the caller to choose the depth of the serialization. See <see cref="Microsoft.Rest.ClientRuntime.SerializationMode"/>.</param>
        /// <returns>
        /// a serialized instance of <see cref="UserStatusResourceResourceUsageSummary" /> as a <see cref="Carbon.Json.JsonNode" />.
        /// </returns>
        public Carbon.Json.JsonNode ToJson(Carbon.Json.JsonObject container, Microsoft.Rest.ClientRuntime.SerializationMode serializationMode)
        {
            container = container ?? new Carbon.Json.JsonObject();

            bool returnNow = false;

            BeforeToJson(ref container, ref returnNow);
            if (returnNow)
            {
                return(container);
            }
            AddIf(null != ResourceDomain ? (Carbon.Json.JsonNode)ResourceDomain.ToJson(null) : null, "resource_domain", container.Add);
            AfterToJson(ref container);
            return(container);
        }
Exemple #9
0
        public void UpdateWithExistingDto_ValueIsUpdated()
        {
            var repo = new Mock <IResourceRepository>();

            repo.Setup(x => x.Get("foo", "foo")).Returns(new Resource {
                Key = "foo", Partition = "foo", Value = "foo"
            });
            var domain = new ResourceDomain(repo.Object);

            domain.Update(new ResourceDto {
                Key = "foo", Partition = "foo", Value = "bar"
            });

            repo.Verify(x => x.Update(It.Is <Resource>(y => y.Key == "foo" && y.Partition == "foo" && y.Value == "bar")));
        }
Exemple #10
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));
        }
Exemple #11
0
        public void GetResourceDto()
        {
            const string partition = "part1";
            var          repo      = new Mock <IResourceRepository>();
            var          res1      = new Resource {
                Partition = partition, Key = "a", Value = "foo1"
            };

            repo.Setup(x => x.Get(res1.Key, res1.Partition)).Returns(res1);

            var domain = new ResourceDomain(repo.Object);

            var dto = domain.Get("part1", "a");

            dto.ShouldNotBeNull();
            dto.Partition.ShouldBe(partition);
            dto.Key.ShouldBe("a");
            dto.Value.ShouldBe("foo1");
        }
Exemple #12
0
        public void ListItems_AreMapped()
        {
            var repo = new Mock <IResourceRepository>();

            repo.Setup(x => x.List("part1"))
            .Returns(new List <Resource> {
                new Resource {
                    Key = "key1", Partition = "part1", Value = "value1"
                }
            });
            var domain = new ResourceDomain(repo.Object);

            var items = domain.List("part1").ToList();

            items.Count.ShouldBe(1);
            items[0].Key       = "key1";
            items[0].Partition = "part1";
            items[0].Value     = "value1";
        }
Exemple #13
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));
        }
Exemple #14
0
        public AsyncResult <T> LoadResource <T>(ResourceType <T> type, IKeyed holder, AttachmentKey key, ResourceDomain domain)
        {
            var result  = new AsyncResult <T>();
            var request = new LoadRequest(type, holder, key, domain, result);

            _loadRequests.Enqueue(request);
            return(result);
        }
Exemple #15
0
 public static void Init(ResourceDomain domain)
 {
     GlobalResourceManager.Instance = new ResourceManager(domain);
 }
Exemple #16
0
 public ResourceManager(ResourceDomain environment)
 {
     Environment = environment;
 }
Exemple #17
0
 private ResourceName(int token, ResourceDomain domain)
     : this()
 {
     Domain  = domain;
 }
Exemple #18
0
        public void CreateWithNullDto_ThrowsBadRequestException()
        {
            var domain = new ResourceDomain(null);

            Should.Throw <BadRequestException>(() => domain.Create(null));
        }