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]));
            }
        }
        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)));
            }
        }
Esempio n. 3
0
        private void InitializeInput()
        {
            var input = GetComponent <IInputInterface>();

            var rawInputs = DefaultTranslatedInputRepository.GetDefaultMappings()
                            .Select(defaultInput => defaultInput.Key).ToList();

            input.SetInputMappingProvider(new DefaultInputMappingProvider(rawInputs, new DefaultTranslatedInputRepository(new PlayerPrefsRepository())));
            input.SetUnityInputInterface(new DefaultUnityInput());
        }
        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]));
            }
        }
        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));
            }
        }