Esempio n. 1
0
        public void GetVersion(string actual, string expected)
        {
            m_NativePlatformMock.Setup(x => x.GetVersion()).Returns(actual);
            var platform = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            Assert.That(platform.Version, Is.EqualTo(expected), "GetVersion failed to return the correct value");
        }
Esempio n. 2
0
        public void IsInitialize(bool actual, bool expected)
        {
            m_NativePlatformMock.Setup(x => x.IsInitialized()).Returns(actual);
            var platform = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            Assert.That(platform.IsInitialized, Is.EqualTo(expected), "IsInitialized did not return the correct value");
        }
Esempio n. 3
0
        public void NativePlatformInitialize(string gameId, bool testMode, bool loadEnabled)
        {
            m_NativePlatformMock.Setup(x => x.Initialize(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <IUnityAdsInitializationListener>()));
            var platform = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            platform.Initialize(gameId, testMode, loadEnabled, null);
            m_NativePlatformMock.Verify(x => x.Initialize(It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <bool>(), It.IsAny <IUnityAdsInitializationListener>()), Times.Once(), "NativePlatform.Initialize() was not called as expected");
        }
Esempio n. 4
0
        public void SetDebugMode(bool actual, bool expected)
        {
            m_NativePlatformMock.Setup(x => x.SetDebugMode(It.IsAny <bool>()));
            var platform = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            platform.DebugMode = actual;
            m_NativePlatformMock.Verify(x => x.SetDebugMode(It.IsAny <bool>()), Times.Once(), "NativePlatform.SetDebugMode(bool) was not called as expected");
        }
Esempio n. 5
0
        public void GetDebugMode(bool actual, bool expected)
        {
            m_NativePlatformMock.Setup(x => x.GetDebugMode()).Returns(actual);
            var platform = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            Assert.That(platform.DebugMode, Is.EqualTo(expected), "GetDebugMode did not return the correct value");
            m_NativePlatformMock.Verify(x => x.GetDebugMode(), Times.Once(), "NativePlatform.GetDebugMode() was not called as expected");
        }
Esempio n. 6
0
        public void NativePlatformGetPlacementState(string placementId)
        {
            m_NativePlatformMock.Setup(x => x.GetPlacementState(It.IsAny <string>()));
            var platform = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            platform.GetPlacementState(placementId);
            m_NativePlatformMock.Verify(x => x.GetPlacementState(It.IsAny <string>()), Times.Once(), "NativePlatform.GetPlacementState() was not called as expected");
        }
Esempio n. 7
0
        public void NativePlatformLoad(string placementId)
        {
            m_NativePlatformMock.Setup(x => x.Load(It.IsAny <string>(), It.IsAny <IUnityAdsLoadListener>()));
            var platform = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            platform.Load(placementId, null);
            m_NativePlatformMock.Verify(x => x.Load(It.IsAny <string>(), It.IsAny <IUnityAdsLoadListener>()), Times.Once(), "NativePlatform.Load() was not called as expected");
        }
Esempio n. 8
0
        public void NativePlatformLoadError(string placementId)
        {
            m_NativePlatformMock.Setup(x => x.Load(It.IsAny <string>(), It.IsAny <IUnityAdsLoadListener>()));
            var platform = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            platform.Load(placementId, null);
            LogAssert.Expect(LogType.Error, "placementId cannot be nil or empty");
            m_NativePlatformMock.Verify(x => x.Load(It.IsAny <string>(), It.IsAny <IUnityAdsLoadListener>()), Times.Never(), "NativePlatform.Load() was called when it should not have been");
        }
Esempio n. 9
0
        public void NativePlatformSetMetaData()
        {
            var metaData = new MetaData("TestMeta");

            metaData.Set("key1", "value1");

            m_NativePlatformMock.Setup(x => x.SetMetaData(It.IsAny <MetaData>()));
            var platform = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            platform.SetMetaData(metaData);
            m_NativePlatformMock.Verify(x => x.SetMetaData(It.IsAny <MetaData>()), Times.Once(), "NativePlatform.SetMetaData() was not called as expected");
        }
Esempio n. 10
0
        public void NativePlatformAddAndRemoveListener()
        {
            var platform     = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);
            var testListener = new UnityAdsTestListener(null, null, null, null);

            Assert.That(platform.Listeners, Is.Not.Null, "The list of Listeners should not be null if the platform has been created");

            platform.AddListener(testListener);
            Assert.That(platform.Listeners.Count, Is.EqualTo(1), "Incorrect number of listeners");

            platform.RemoveListener(testListener);
            Assert.That(platform.Listeners.Count, Is.EqualTo(0), "Incorrect number of listeners");
        }
Esempio n. 11
0
        public IEnumerator UnityAdsDidError(string testPlacementId)
        {
            var hasCalledListener = false;
            var platform          = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            platform.AddListener(new UnityAdsTestListener(null, (placementId) => {
                Assert.That(placementId, Is.EqualTo(testPlacementId), "The placementId under test should have been the placement id that is returned in Error");
                hasCalledListener = true;
            }, null, null));
            platform.UnityAdsDidError(testPlacementId);
            while (!hasCalledListener)
            {
                yield return(null);
            }
            Assert.That(hasCalledListener, Is.True, "The OnUnityAdsDidError callback should have called");
            m_CoroutineExecutorMock.Verify(x => x.Post(It.IsAny <Action>()), Times.Once(), "Calls should happen on the main thread and should all batched together as 1 call");
        }
Esempio n. 12
0
        public IEnumerator OnStartCallbackSetsIsShowingOnAdStart(string testPlacementId)
        {
            var hasCalledListener = false;
            var platform          = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            platform.AddListener(new UnityAdsTestListener(null, null, (placementId) => {
                Assert.That(placementId, Is.EqualTo(testPlacementId), "The placementId under test should have been the placement id that is returned Starting");
                hasCalledListener = true;
            }, null));
            platform.Initialize("1234567", false, false, null);
            platform.UnityAdsDidStart(testPlacementId);
            while (!hasCalledListener)
            {
                yield return(null);
            }
            Assert.That(hasCalledListener, Is.True, "The OnUnityAdsDidStart callback should have called");
            Assert.That(platform.IsShowing, Is.True, "IsShowing should be set to true after starting to show an ad");
            m_CoroutineExecutorMock.Verify(x => x.Post(It.IsAny <Action>()), Times.Once(), "Calls should happen on the main thread and should all batched together as 1 call");
        }
Esempio n. 13
0
        public IEnumerator ShowOptionsGamerSid(string expectedGamerSid)
        {
            var setMetaDataCalled = false;
            var platform          = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            m_NativePlatformMock.Setup(x => x.SetMetaData(It.IsAny <MetaData>())).Callback <MetaData>(result => {
                Assert.That(result.category, Is.EqualTo("player"), "The category player should exist if gamerSid was stored properly");
                Assert.That(result.Get("server_id"), Is.EqualTo(expectedGamerSid), "GamerSid was not stored properly in MetaData");
                setMetaDataCalled = true;
            });

            var showOptions = new ShowOptions();

            showOptions.gamerSid += expectedGamerSid;
            platform.Show("placementId", showOptions, null);
            m_NativePlatformMock.Verify(x => x.SetMetaData(It.IsAny <MetaData>()), Times.Once(), "Set MetaData should have been called with the gamerSid");
            while (!setMetaDataCalled)
            {
                yield return(null);
            }
            Assert.That(setMetaDataCalled, Is.True, "The SetMetaData function should have been called");
        }
Esempio n. 14
0
        public IEnumerator UnityAdsDidFinishShowOptionsInvoked(string expectedPlacementId, ShowResult expectedShowResult)
        {
            var hasCalledListener = false;
            var platform          = new Platform.Platform(m_NativePlatformMock.Object, m_BannerMock.Object, m_CoroutineExecutorMock.Object);

            m_NativePlatformMock.Setup(x => x.Show(It.IsAny <string>(), null)).Callback(() => {
                platform.UnityAdsDidFinish(expectedPlacementId, expectedShowResult);
            });

            var showOptions = new ShowOptions();

            showOptions.resultCallback += result => {
                Assert.That(result, Is.EqualTo(expectedShowResult), "resultCallback showOption should match the expected value.");
                hasCalledListener = true;
            };
            platform.Show(expectedPlacementId, showOptions, null);
            while (!hasCalledListener)
            {
                yield return(null);
            }
            Assert.That(hasCalledListener, Is.True, "The hideCallback should have been called");
            m_CoroutineExecutorMock.Verify(x => x.Post(It.IsAny <Action>()), Times.Once(), "Calls should happen on the main thread and should all batched together as 1 call");
        }
Esempio n. 15
0
 private void Start()
 {
     _platform = FindObjectOfType <Platform.Platform>();
 }