Пример #1
0
        private void CreateItem(string itemType, EntityConfig node, SimulationLifecycleManager lifecycleManager, out ComponentEntityTuple <IItemType, CurrentLocation> item, out int itemContainerIndex, out ItemContainer itemContainer)
        {
            // store current match
            var itemLocationMatcher        = lifecycleManager.ECSRoot.ECS.MatcherProvider.CreateMatcherGroup <IItemType, CurrentLocation>();
            var priorMatchignEntitiesTotal = itemLocationMatcher.MatchingEntities.Length;

            // Add Items to swap
            var createItem = new CreateItem(TutorialScanner.Archetype.Name,
                                            node);

            createItem.Execute(lifecycleManager.ECSRoot.ECS,
                               lifecycleManager.ECSRoot.Configuration);

            // Tick so commands get processed
            lifecycleManager.ECSRoot.ECS.Tick();

            item = itemLocationMatcher.MatchingEntities[priorMatchignEntitiesTotal];

            // Get the subsystem the item's current location is set to
            var systemWithStorageMatcher = lifecycleManager.ECSRoot.ECS.MatcherProvider.CreateMatcherGroup <Subsystem, ItemStorage>();

            systemWithStorageMatcher.TryGetMatchingEntity(item.Component2.Value.Value,
                                                          out var subsystemTuple);

            var itemLocal = item;

            itemContainerIndex = Array.FindIndex(subsystemTuple.Component2.Items,
                                                 ic => ic.Item == itemLocal.Entity.Id);

            itemContainer = subsystemTuple.Component2.Items[itemContainerIndex];
        }
Пример #2
0
        private static void VerifyDriveEnumerationWarningLoggedUponCreateItemExecution(string itemSpec)
        {
            using (var env = TestEnvironment.Create())
            {
                Helpers.ResetStateForDriveEnumeratingWildcardTests(env, "0");

                try
                {
                    MockEngine engine = new MockEngine();
                    CreateItem t      = new CreateItem()
                    {
                        BuildEngine = engine,
                        Include     = new ITaskItem[] { new TaskItem(itemSpec) },
                    };

                    t.Execute().ShouldBeTrue();
                    engine.Warnings.ShouldBe(1);
                    engine.AssertLogContains("MSB5029");
                }
                finally
                {
                    ChangeWaves.ResetStateForTests();
                }
            }
        }
Пример #3
0
        public void WildcardDriveEnumerationTaskItemLogsError(string itemSpec)
        {
            using (var env = TestEnvironment.Create())
            {
                Helpers.ResetStateForDriveEnumeratingWildcardTests(env, "1");

                try
                {
                    MockEngine engine = new MockEngine();
                    CreateItem t      = new CreateItem()
                    {
                        BuildEngine = engine,
                        Include     = new ITaskItem[] { new TaskItem(itemSpec) },
                    };

                    t.Execute().ShouldBeFalse();
                    engine.Errors.ShouldBe(1);
                    engine.AssertLogContains("MSB5029");
                }
                finally
                {
                    ChangeWaves.ResetStateForTests();
                }
            }
        }
Пример #4
0
        public void UnspecifiedFromUnspecifiedIsEmpty()
        {
            CreateItem t = new CreateItem();

            t.BuildEngine = new MockEngine();

            bool success = t.Execute();

            Assert.IsTrue(success);
            Assert.AreEqual(0, t.Include.Length);
        }
Пример #5
0
        public void UnspecifiedFromUnspecifiedIsEmpty()
        {
            CreateItem t = new CreateItem();

            t.BuildEngine = new MockEngine();

            bool success = t.Execute();

            Assert.True(success);
            Assert.Empty(t.Include);
        }
Пример #6
0
        public void OneFromUnspecifiedIsEmpty()
        {
            CreateItem t = new CreateItem();

            t.BuildEngine = new MockEngine();

            t.Exclude = new ITaskItem[] { new TaskItem("MyFile.txt") };

            bool success = t.Execute();

            Assert.IsTrue(success);
            Assert.AreEqual(0, t.Include.Length);
        }
Пример #7
0
        public void UnspecifiedFromOneIsOne()
        {
            CreateItem t = new CreateItem();

            t.BuildEngine = new MockEngine();

            t.Include = new ITaskItem[] { new TaskItem("MyFile.txt") };

            bool success = t.Execute();

            Assert.IsTrue(success);
            Assert.AreEqual(1, t.Include.Length);
            Assert.AreEqual(t.Include[0].ItemSpec, t.Include[0].ItemSpec);
        }
Пример #8
0
        public void AdditionalMetaData()
        {
            CreateItem t = new CreateItem();

            t.BuildEngine = new MockEngine();

            t.Include            = new ITaskItem[] { new TaskItem("MyFile.txt") };
            t.AdditionalMetadata = new string[] { "MyMetaData=SomeValue" };

            bool success = t.Execute();

            Assert.IsTrue(success);
            Assert.AreEqual("SomeValue", t.Include[0].GetMetadata("MyMetaData"));
        }
Пример #9
0
        public void CaseDoesntMatter()
        {
            CreateItem t = new CreateItem();

            t.BuildEngine = new MockEngine();

            t.Include = new ITaskItem[] { new TaskItem("MyFile.txt") };
            t.Exclude = new ITaskItem[] { new TaskItem("myfile.tXt") };

            bool success = t.Execute();

            Assert.IsTrue(success);
            Assert.AreEqual(0, t.Include.Length);
        }
Пример #10
0
        public void OneFromOneIsZero()
        {
            CreateItem t = new CreateItem();

            t.BuildEngine = new MockEngine();

            t.Include = new ITaskItem[] { new TaskItem("MyFile.txt") };
            t.Exclude = new ITaskItem[] { new TaskItem("MyFile.txt") };

            bool success = t.Execute();

            Assert.True(success);
            Assert.Equal(0, t.Include.Length);
        }
Пример #11
0
        public void OneFromOneMismatchIsOne()
        {
            CreateItem t = new CreateItem();

            t.BuildEngine = new MockEngine();

            t.Include = new ITaskItem[] { new TaskItem("MyFile.txt") };
            t.Exclude = new ITaskItem[] { new TaskItem("MyFileOther.txt") };

            bool success = t.Execute();

            Assert.IsTrue(success);
            Assert.AreEqual(1, t.Include.Length);
            Assert.AreEqual("MyFile.txt", t.Include[0].ItemSpec);
        }
Пример #12
0
        private string[] GetFiles(string localPath, string glob)
        {
            var createItemTask = new CreateItem
            {
                BuildEngine = BuildEngine,
                Include     = new[]
                {
                    new TaskItem(Path.Combine(localPath, glob))
                }
            };

            if (!createItemTask.Execute())
            {
                throw new Exception(
                          $"Failed to create items with localPath '{localPath}', glob '{glob}'");
            }

            return(createItemTask.Include.Select(item => item.ItemSpec).ToArray());
        }
Пример #13
0
        public void AdditionalMetaDataPreserveExisting()
        {
            CreateItem t = new CreateItem();

            t.BuildEngine = new MockEngine();

            TaskItem item = new TaskItem("MyFile.txt");

            item.SetMetadata("MyMetaData", "SomePreserveMeValue");

            t.Include = new ITaskItem[] { item };
            t.PreserveExistingMetadata = true;

            t.AdditionalMetadata = new string[] { "MyMetaData=SomeValue" };

            bool success = t.Execute();

            Assert.IsTrue(success);
            Assert.AreEqual("SomePreserveMeValue", t.Include[0].GetMetadata("MyMetaData"));
        }
Пример #14
0
        public void AdditionalMetaDataOverwriteExisting()
        {
            CreateItem t = new CreateItem();

            t.BuildEngine = new MockEngine();

            TaskItem item = new TaskItem("MyFile.txt");

            item.SetMetadata("MyMetaData", "SomePreserveMeValue");

            t.Include = new ITaskItem[] { item };

            // The default for CreateItem is to overwrite any existing metadata
            // t.PreserveExistingMetadata = false;

            t.AdditionalMetadata = new string[] { "MyMetaData=SomeOverwriteValue" };

            bool success = t.Execute();

            Assert.True(success);
            Assert.Equal("SomeOverwriteValue", t.Include[0].GetMetadata("MyMetaData"));
        }