コード例 #1
0
        public void DefaultTranslatedInputRepository_RetrieveMappingsForRawInputs_ReturnsExpectedMappings()
        {
            var mockPlayerPrefsRepoInterface = Substitute.For <IPlayerPrefsRepositoryInterface>();

            const EInputKey expectedInputKey = EInputKey.Interact;

            var expectedRawInputs = new List <RawInput>
            {
                new RawInput("Test", EInputType.Button),
                new RawInput("Test2", EInputType.Analog)
            };

            foreach (var expectedRawInput in expectedRawInputs)
            {
                mockPlayerPrefsRepoInterface.GetValueForKey(Arg.Any <string>())
                .Returns(expectedInputKey.ToString());
            }

            var defaultTranslatedInputRepo = new DefaultTranslatedInputRepository(mockPlayerPrefsRepoInterface);
            var actualMappings             = defaultTranslatedInputRepo.RetrieveMappingsForRawInputs(expectedRawInputs);

            foreach (var expectedRawInput in expectedRawInputs)
            {
                Assert.IsTrue(ObjectComparisonExtensions.EqualByPublicProperties(actualMappings[expectedRawInput], new TranslatedInput(expectedInputKey, expectedRawInput.InputType)));
            }
        }
コード例 #2
0
        public void DefaultTranslatedInputRepository_RetrieveMappingsForRawInputs_NoMappingsReturnsDefaultMappings()
        {
            var mockPlayerPrefsRepoInterface = Substitute.For <IPlayerPrefsRepositoryInterface>();

            var expectedRawInputs = new List <RawInput>
            {
                new RawInput("Test", EInputType.Button),
                new RawInput("Test2", EInputType.Analog)
            };

            const string nullString = null;

            foreach (var expectedRawInput in expectedRawInputs)
            {
                mockPlayerPrefsRepoInterface.GetValueForKey(Arg.Is(expectedRawInput.InputName))
                .Returns(nullString);
            }

            var defaultTranslatedInputRepo = new DefaultTranslatedInputRepository(mockPlayerPrefsRepoInterface);
            var actualMappings             = defaultTranslatedInputRepo.RetrieveMappingsForRawInputs(expectedRawInputs);

            foreach (var mapping in actualMappings)
            {
                Assert.IsTrue(ObjectComparisonExtensions.EqualByPublicProperties(mapping.Value, defaultTranslatedInputRepo.DefaultMappings[mapping.Key]));
            }
        }
コード例 #3
0
        public void DefaultTranslatedInputRepository_RetrieveMappingsForRawInputs_NoRawInputsReturnsDefaultMappings()
        {
            var mockPlayerPrefsRepoInterface = Substitute.For <IPlayerPrefsRepositoryInterface>();

            var emptyRawInputs = new List <RawInput>();

            var defaultTranslatedInputRepo = new DefaultTranslatedInputRepository(mockPlayerPrefsRepoInterface);
            var actualMappings             = defaultTranslatedInputRepo.RetrieveMappingsForRawInputs(emptyRawInputs);

            foreach (var mapping in actualMappings)
            {
                Assert.IsTrue(ObjectComparisonExtensions.EqualByPublicProperties(mapping.Value, defaultTranslatedInputRepo.DefaultMappings[mapping.Key]));
            }
        }
コード例 #4
0
        public void DefaultTranslatedInputRepository_RetrieveMappingsForRawInputs_UsesInRawInputs()
        {
            var mockPlayerPrefsRepoInterface = Substitute.For <IPlayerPrefsRepositoryInterface>();
            var expectedRawInputs            = new List <RawInput>
            {
                new RawInput("Test", EInputType.Button),
                new RawInput("Test2", EInputType.Analog)
            };

            mockPlayerPrefsRepoInterface.GetValueForKey(Arg.Any <string>()).Returns(EInputKey.Interact.ToString());

            var defaultTranslatedInputRepo = new DefaultTranslatedInputRepository(mockPlayerPrefsRepoInterface);

            defaultTranslatedInputRepo.RetrieveMappingsForRawInputs(expectedRawInputs);

            foreach (var expectedRawInput in expectedRawInputs)
            {
                mockPlayerPrefsRepoInterface.Received().GetValueForKey(Arg.Is(expectedRawInput.InputName));
            }
        }