Example #1
0
        public void When_user_has_accepted_cookies_then_no_popup_is_to_be_displayed()
        {
            GivenTheUserHasAcceptedCookies();

            var result = TestInstance.GetCookiePopup();

            result.ShouldSatisfyAllConditions(() =>
            {
                result.ShowPopup.ShouldBe(false);
                result.Message.ShouldBe(string.Empty);
            });
        }
Example #2
0
        private DirectoryInfo Build(TestInstance testInstance)
        {
            var result = new BuildCommand(
                projectPath: Path.Combine(testInstance.TestRoot, "PortableApp"))
                         .ExecuteWithCapturedOutput();

            result.Should().Pass();

            var outputBase = new DirectoryInfo(Path.Combine(testInstance.TestRoot, "PortableApp", "bin", "Debug"));

            return(outputBase.Sub("netcoreapp1.0"));
        }
        public async Task RetrieveAsync_BuilderSpecified_DelegatedToRepository()
        {
            MockedTestInstance.Setup(_ => _.GetRepository <IData>()).Returns(DataRepository);
            MockedDataRepository.Setup(_ =>
                                       _.RetrieveAsync(It.IsAny <ITerminalDescriptor>(), It.IsAny <IDataBuilder <IData> >()))
            .Returns(Task.FromResult(Data));

            var result = await TestInstance.RetrieveAsync <IData>(TerminalDescriptor, DataBuilder);

            Assert.AreSame(Data, result);
            MockedDataRepository.Verify(_ => _.RetrieveAsync(TerminalDescriptor, DataBuilder));
        }
Example #4
0
 public void BuildSingleProject(TestInstance instance)
 {
     foreach (var iteration in Benchmark.Iterations)
     {
         var buildCommand = new BuildCommand(instance.TestRoot, buildProfile: false);
         using (iteration.StartMeasurement())
         {
             buildCommand.Execute().Should().Pass();
         }
         TouchSource(instance.TestRoot);
     }
 }
        public void ProjectWithContentsTest()
        {
            TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithContents")
                                    .WithLockFiles()
                                    .WithBuildArtifacts();

            var testProject    = _getProjectJson(instance.TestRoot, "TestAppWithContents");
            var publishCommand = new PublishCommand(testProject);

            publishCommand.Execute().Should().Pass();
            publishCommand.GetOutputDirectory().Should().HaveFile("testcontentfile.txt");
        }
        public void PublishInstanceChangedEvent__CorrectlyPublished()
        {
            var correctlyPublished = false;
            var givenArgs          = new InstanceChangedEventArgs <IData>(TerminalDescriptor, Data);

            TestInstance.InstanceChangedEvent += (sender, args) =>
                                                 correctlyPublished = sender == TestInstance && args == givenArgs;

            TestInstance.PublishInstanceChangedEvent(givenArgs);

            Assert.IsTrue(correctlyPublished);
        }
Example #7
0
        /// <summary>
        /// Called when a test has completed. By default saves artifacts and calles CreateReport
        /// </summary>
        /// <param name="Result"></param>
        /// <returns></returns>
        public override void StopTest(bool WasCancelled)
        {
            base.StopTest(WasCancelled);

            // Shutdown the instance so we can access all files, but do not null it or shutdown the UnrealApp because we still need
            // access to these objects and their resources! Final cleanup is done in CleanupTest()
            TestInstance.Shutdown();

            try
            {
                Log.Info("Saving artifacts to {0}", ArtifactPath);
                Directory.CreateDirectory(ArtifactPath);
                Utils.SystemHelpers.MarkDirectoryForCleanup(ArtifactPath);

                SessionArtifacts = SaveRoleArtifacts(ArtifactPath);

                // call legacy version
                SaveArtifacts_DEPRECATED(ArtifactPath);
            }
            catch (Exception Ex)
            {
                Log.Warning("Failed to save artifacts. {0}", Ex);
            }

            try
            {
                // Artifacts have been saved, release devices back to pool for other tests to use
                UnrealApp.ReleaseDevices();
            }
            catch (Exception Ex)
            {
                Log.Warning("Failed to release devices. {0}", Ex);
            }

            try
            {
                CreateReport(GetTestResult(), Context, Context.BuildInfo, SessionArtifacts, ArtifactPath);
            }
            catch (Exception Ex)
            {
                Log.Warning("Failed to save completion report. {0}", Ex);
            }

            try
            {
                SubmitToDashboard(GetTestResult(), Context, Context.BuildInfo, SessionArtifacts, ArtifactPath);
            }
            catch (Exception Ex)
            {
                Log.Warning("Failed to submit results to dashboard. {0}", Ex);
            }
        }
    void OnGUI()
    {
        GUI.Label(new Rect(Screen.width / 2 - 100, 0, 200, 40), "数量:" + m_count, m_style);

        if (GUI.Button(new Rect(10, 10, 150, 60), "加载3D动画", m_style1))
        {
            if (m_Ani != null)
            {
                GameObject.DestroyImmediate(m_Ani);
                m_Ani = null;
            }
            m_Ani = Instantiate(Ani3D);
            TestInstance ins = m_Ani.GetComponent <TestInstance>();
            ins.m_w = m_w;
            ins.m_h = m_h;
            m_count = (int)m_w * (int)m_h;
        }

        if (GUI.Button(new Rect(10, 100, 150, 60), "加载2D动画", m_style1))
        {
            if (m_Ani != null)
            {
                GameObject.DestroyImmediate(m_Ani);
                m_Ani = null;
            }
            m_Ani = Instantiate(Ani2D);
            Ani2D ins = m_Ani.GetComponent <Ani2D>();
            ins.m_w = m_w;
            ins.m_h = m_h;
            m_count = (int)m_w * (int)m_h;
        }

        if (GUI.Button(new Rect(10, 190, 150, 60), "加载combine 2D动画", m_style1))
        {
            if (m_Ani != null)
            {
                GameObject.DestroyImmediate(m_Ani);
                m_Ani = null;
            }
            m_Ani = Instantiate(CombineAni2D);
            CombineMesh2DAni ins = m_Ani.GetComponent <CombineMesh2DAni>();
            ins.m_w = m_w / 6 + 1;
            ins.m_h = m_h / 6 + 1;
            m_count = (int)m_w * (int)m_h;
        }


        GUI.Label(new Rect(Screen.width / 2 - 100, 100, 200, 40), "Width", m_style);
        m_w = GUI.HorizontalSlider(new Rect(Screen.width / 2, 100, 400, 40), m_w, 1.0f, 100.0f);
        GUI.Label(new Rect(Screen.width / 2 - 100, 150, 200, 40), "Height", m_style);
        m_h = GUI.HorizontalSlider(new Rect(Screen.width / 2, 150, 400, 40), m_h, 1.0f, 100.0f);
    }
        public async Task FillCollectionAsync__CollectionFilledWithData()
        {
            MockedTestInstance.Setup(_ => _.RegisterCollection(It.IsAny <ICollection <IData> >(),
                                                               It.IsAny <INonTerminalDescriptor>(), It.IsAny <IDataBuilder <IData> >()));
            MockedTestInstance.Setup(_ => _.FillCollectionWithData(It.IsAny <ICollection <IData> >(),
                                                                   It.IsAny <INonTerminalDescriptor>()));
            MockedTestInstance.Setup(_ => _.BuildCollectionAsync(It.IsAny <ICollection <IData> >()))
            .Returns(Task.FromResult(0));

            await TestInstance.FillCollectionAsync(new FillCollectionArgs <IData>(Collection, Descriptor));

            MockedTestInstance.Verify(_ => _.FillCollectionWithData(Collection, Descriptor));
        }
        public async Task ChangeBuilderAsync__DelegatedToRepository()
        {
            var awaited = false;

            MockedDataRepository.Setup(_ =>
                                       _.ChangeBuilderAsync(It.IsAny <ICollection <IData> >(), It.IsAny <IDataBuilder <IData> >()))
            .Returns(Task.Delay(10).ContinueWith(_ => awaited = true));

            await TestInstance.ChangeBuilderAsync(Collection, DataBuilder);

            MockedDataRepository.Verify(_ => _.ChangeBuilderAsync(Collection, DataBuilder));
            Assert.IsTrue(awaited);
        }
        public async Task FillCollectionAsync__Builder_AlreadyRegisteredWithDescriptor_CollectionNotEmpty__ChangeBuilderDelegatedToRepository()
        {
            MockedCollection.Setup(_ => _.Count).Returns(RandomizationHelper.Instance.GetInt());
            MockedTestInstance.Setup(_ =>
                                     _.IsCollectionRegisteredWithDescriptor(It.IsAny <ICollection <IData> >(),
                                                                            It.IsAny <INonTerminalDescriptor>())).Returns(true);
            MockedDataRepository.Setup(_ => _.FillCollectionAsync(It.IsAny <IFillCollectionArgs <IData> >()))
            .Returns(Task.FromResult(0));

            await TestInstance.FillCollectionAsync(Collection, Descriptor, DataBuilder);

            MockedDataRepository.Verify(_ => _.ChangeBuilderAsync(Collection, DataBuilder), Times.Once);
        }
        public async Task FillCollectionAsync__NoBuilder_AlreadyRegisteredWithDescriptor_CollectionEmpty__DelegatedToRepository()
        {
            MockedCollection.Setup(_ => _.Count).Returns(0);
            MockedTestInstance.Setup(_ =>
                                     _.IsCollectionRegisteredWithDescriptor(It.IsAny <ICollection <IData> >(),
                                                                            It.IsAny <INonTerminalDescriptor>())).Returns(true);
            MockedDataRepository.Setup(_ => _.FillCollectionAsync(It.IsAny <IFillCollectionArgs <IData> >()))
            .Returns(Task.FromResult(0));

            await TestInstance.FillCollectionAsync(Collection, Descriptor);

            MockedDataRepository.Verify(_ => _.FillCollectionAsync(It.IsAny <IFillCollectionArgs <IData> >()));
        }
        public void IsCollectionRegistered__DelegatedToRepository()
        {
            var expectedResult = RandomizationHelper.Instance.GetBool();

            MockedTestInstance.Setup(_ => _.GetRepository <IData>()).Returns(DataRepository);
            MockedDataRepository.Setup(_ => _.IsCollectionRegistered(It.IsAny <ICollection <IData> >()))
            .Returns(expectedResult);

            var result = TestInstance.IsCollectionRegistered(Collection);

            Assert.AreEqual(expectedResult, result);
            MockedDataRepository.Verify(_ => _.IsCollectionRegistered(Collection));
        }
        public void Create_DifferentIntrinsicStates_DifferentInstancesForEachState()
        {
            var intrinsicStateOne = new object();
            var intrinsicStateTwo = new object();

            TestInstanceMockProtected
            .Setup <ITerminalDescriptor>("Instantiate", ItExpr.IsAny <object>())
            .Returns(() => new Mock <ITerminalDescriptor>().Object);

            Assert.AreSame(TestInstance.Create(intrinsicStateOne), TestInstance.Create(intrinsicStateOne));
            Assert.AreSame(TestInstance.Create(intrinsicStateTwo), TestInstance.Create(intrinsicStateTwo));
            Assert.IsFalse(ReferenceEquals(TestInstance.Create(intrinsicStateOne), TestInstance.Create(intrinsicStateTwo)));
        }
        public void Create_UnknownIntrinsicState_InstantiatedAndReturned()
        {
            var intrinsicState     = new object();
            var terminalDescriptor = new Mock <ITerminalDescriptor>().Object;

            TestInstanceMockProtected
            .Setup <ITerminalDescriptor>("Instantiate", intrinsicState)
            .Returns(terminalDescriptor);

            var result = TestInstance.Create(intrinsicState);

            Assert.AreSame(terminalDescriptor, result);
        }
Example #16
0
        public void KeyIsRecommendedLengthWhenEncoded(string encodedKey, byte[] hmacHash)
        {
            "When I create a secret key"
            .x(() => encodedKey = TestInstance.CreateKey());

            "And an HMAC hash"
            .x(() => hmacHash = Container.Resolve <TotpTokenBuilder>().GenerateSha1Hash(
                   Faker.Random.Bytes(_hmacKeyByteCount),
                   BitConverter.GetBytes(Faker.Random.Long(1500000000, 1600000000))));

            "Then the secret key is the length of the HMAC output as specified in RFC 6238"
            .x(() => TestInstance.DecodeKey(encodedKey).Length.ShouldBe(hmacHash.Length));
        }
Example #17
0
        public async Task AcknowledgeStaleDataAsync__StaleDataRefreshed()
        {
            var awaited = false;

            MockedDataRefresher.Setup(_ => _.RefreshAsync(It.IsAny <IDescriptor>()))
            .Returns(Task.Delay(10).ContinueWith(_ => awaited = true));

            await TestInstance.AcknowledgeStaleDataAsync(Descriptor);

            MockedDataRefresher.Verify(_ => _.RefreshAsync(Descriptor));

            Assert.IsTrue(awaited);
        }
Example #18
0
        public void TestReadInstanceData()
        {
            var instance = new TestInstance {
                Serialized = "aaa", NonSerialized = "bbb"
            };

            log.WriteInstanceData(instance);
            var instance2 = logReader.ReadInstanceData() as TestInstance;

            Assert.NotNull(instance2);
            Assert.Equal(instance.Serialized, instance2.Serialized);
            Assert.True(string.IsNullOrEmpty(instance2.NonSerialized));
        }
        public void UndoRotation(double leftRotation)
        {
            leftRotation = Faker.Random.Double(1, 360);

            $"Given a rotation angle of {leftRotation} degrees"
            .x(() => TestInstance.LeftRotation = leftRotation);

            "When a rotate command is undone"
            .x(() => TestInstance.Undo());

            "Then the robot is issued a command to rotate right the supplied rotation angle"
            .x(() => GetDependency <IRobot>().Verify(d => d.RotateLeft(-leftRotation)));
        }
Example #20
0
        public void UndoScoop()
        {
            const bool scoopUpwards = true;

            $"Given a scoop upwards command of {scoopUpwards}"
            .x(() => TestInstance.ScoopUpwards = scoopUpwards);

            "When a scoop command is undone"
            .x(() => TestInstance.Undo());

            "Then the robot is issued a command to release scoop contents"
            .x(() => GetDependency <IRobot>().Verify(d => d.Scoop(!scoopUpwards)));
        }
Example #21
0
        public void ItRunsAppsThatOutputUnicodeCharacters()
        {
            TestInstance instance = TestAssetsManager.CreateTestInstance("TestAppWithUnicodéPath")
                                    .WithLockFiles()
                                    .WithBuildArtifacts();

            new RunCommand(instance.TestRoot)
            .ExecuteWithCapturedOutput()
            .Should()
            .Pass()
            .And
            .HaveStdOutContaining("Hélló Wórld!");
        }
Example #22
0
        public void ExecuteScoop()
        {
            const bool scoopUpwards = true;

            $"Given a scoop upwards command of {scoopUpwards}"
            .x(() => TestInstance.ScoopUpwards = scoopUpwards);

            "When a scoop command is executed"
            .x(() => TestInstance.Execute());

            "Then the robot is issued a command to scoop"
            .x(() => GetDependency <IRobot>().Verify(d => d.Scoop(scoopUpwards)));
        }
        public override Task <bool> Invoke(TestContext ctx, TestInstance instance, CancellationToken cancellationToken)
        {
            ctx.OnTestRunning();

            if (Builder.ExpectedExceptionType != null)
            {
                return(ExpectingException(ctx, instance, Builder.ExpectedExceptionType, cancellationToken));
            }
            else
            {
                return(ExpectingSuccess(ctx, instance, cancellationToken));
            }
        }
Example #24
0
    public void TestInstanceMethodReturns()
    {
        var testInstance = new TestInstance();

        Assert.AreEqual(1, testInstance.TestMethodReturn1WithoutParameters());
        var expectedResult = 2;

        Mock.Setup(() => testInstance.TestMethodReturn1WithoutParameters(), () =>
        {
            var actualResult = testInstance.TestMethodReturn1WithoutParameters();
            Assert.AreEqual(expectedResult, actualResult);
        }).Returns(expectedResult);
    }
Example #25
0
        public void RotateRight(double rightRotation)
        {
            var rotationDegrees = Faker.Random.Double(-360, -1);

            $"Given a rotation angle of {rotationDegrees} degrees"
            .x(() => rightRotation = rotationDegrees);

            "When a robot is issued a command to rotate"
            .x(() => TestInstance.RotateLeft(rightRotation));

            "Then the robot rotates right"
            .x(() => GetDependency <IConsoleAdapter>().Verify(m => m.WriteLine("Robot rotated right {0} degrees.", -rightRotation), Times.Once()));
        }
Example #26
0
        public void FinishInstanceMovesInstanceFromRunningToFinished()
        {
            var stats    = this.CreateStats(0, 1);
            var instance = new TestInstance($"0");
            var result   = new TestResult(TimeSpan.FromSeconds(42));

            stats.FinishInstance(instance, result).ShouldBeTrue();
            stats.OpenInstances.ShouldBeEmpty();
            stats.FinishedInstances.ContainsKey(instance).ShouldBeTrue();
            stats.FinishedInstances[instance].ShouldBe(result);

            stats.RuntimeOfFinishedInstances.ShouldBe(result.Runtime);
        }
        public void WhenInstanceChanged__InstanceBuilt()
        {
            var terminalDescriptor = new Mock <ITerminalDescriptor>().Object;
            var data = new Mock <IData>().Object;
            var args = new InstanceChangedEventArgs <IData>(terminalDescriptor, data);

            MockedTestInstance.Setup(_ => _.BuildInstanceAsync(It.IsAny <ITerminalDescriptor>(), It.IsAny <IData>()))
            .Returns(Task.FromResult(0));

            TestInstance.WhenInstanceChanged(new object(), args);

            MockedTestInstance.Verify(_ => _.BuildInstanceAsync(terminalDescriptor, data));
        }
Example #28
0
        public void MoveBackwards(int backwardDistance)
        {
            var distanceMillimetres = Faker.Random.Int(-1000, -1);

            $"Given a movement distance of {distanceMillimetres} mm"
            .x(() => backwardDistance = distanceMillimetres);

            "When a robot is issued a command to move"
            .x(() => TestInstance.Move(backwardDistance));

            "Then the robot moves backwards"
            .x(() => GetDependency <IConsoleAdapter>().Verify(m => m.WriteLine("Robot moved backwards {0}mm.", -backwardDistance), Times.Once()));
        }
        public void DropCollection_CollectionRegistered_CollectionDroppedCorrectly()
        {
            MockedTestInstance.Setup(_ => _.IsCollectionRegistered(It.IsAny <ICollection <IData> >())).Returns(true);
            MockedTestInstance.Setup(_ => _.ClearCollection(It.IsAny <ICollection <IData> >()));
            MockedTestInstance.Setup(_ =>
                                     _.DropCollection(It.IsAny <ICollection <IData> >(), It.IsAny <INonTerminalDescriptor>()));
            MockedTestInstance.Setup(_ => _.GetDescriptor(It.IsAny <ICollection <IData> >())).Returns(Descriptor);

            TestInstance.DropCollection(Collection);

            MockedTestInstance.Verify(_ => _.GetDescriptor(Collection));
            MockedTestInstance.Verify(_ => _.DropCollection(Collection, Descriptor));
        }
Example #30
0
        public async Task SingleActivity()
        {
            string input = $"[{DateTime.UtcNow:o}]";

            TestInstance <string> instance = await this.testService.RunOrchestration(
                input,
                orchestrationName : "OrchestrationWithActivity",
                implementation : (ctx, input) => ctx.ScheduleTask <string>("SayHello", "", input),
                activities : ("SayHello", TestService.MakeActivity((TaskContext ctx, string input) => $"Hello, {input}!")));

            OrchestrationState state = await instance.WaitForCompletion(
                expectedOutput : $"Hello, {input}!");
        }
Example #31
0
		public void Configuring_event_listeners_for_nhibernate()
		{
			using (ISession session = SessionFactory.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				session.CreateQuery("Delete TestInstance").ExecuteUpdate();
				session.CreateQuery("Delete TestInstanceAudit").ExecuteUpdate();

				transaction.Commit();
			}

			_channel = new ChannelAdapter();
			_connection = _channel.Connect(x =>
				{
					x.AddConsumersFor<TestInstanceAudit>()
						.BindUsing<TestInstanceAuditBinding, AuditKey>()
						.HandleOnCallingThread()
						.CreateNewInstanceBy(id => new TestInstanceAudit(id))
						.PersistUsingNHibernate()
						.UseSessionProvider(() => SessionFactory.OpenSession());
				});

			ResetSessionFactory();
			ExtraConfiguration = cfg => { cfg.AddAuditEventListeners(_channel); };

			using (ISession session = SessionFactory.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				session.CreateQuery("Delete TestInstance").ExecuteUpdate();

				var instance = new TestInstance(27, 123.45m);
				session.Save(instance);
				instance = new TestInstance(37, 123.45m);
				session.Save(instance);
				instance = new TestInstance(47, 123.45m);
				session.Save(instance);

				transaction.Commit();
			}
		}
Example #32
0
		public void A_message_event_is_raised()
		{
			_workflow = StateMachineWorkflow.New<TestWorkflow, TestInstance>(x =>
			{
				x.AccessCurrentState(y => y.CurrentState);

				x.During(y => y.Initial)
					.When(y => y.Finish)
					.Then(() => _nonInstanceValue = true)
					.Then(instance => instance.MessageValue = "Success")
					.Then((instance, message) => instance.MessageValue = message.Value)
					.TransitionTo(y => y.Completed);
			});

			_testInstance = new TestInstance();

			_instance = _workflow.GetInstance(_testInstance);

			_instance.RaiseEvent(x => x.Finish, new Result
			{
				Value = "Success"
			});
		}
Example #33
0
		public void Configuring_event_listeners_for_nhibernate()
		{
			_channel = new ChannelAdapter();

			_preInsert = new Future<PreInsertEvent<TestInstance>>();
			_preInsertPrevious = new Future<PreInsertEvent<PreviousValue>>();

			_channel.Connect(x =>
			{
				x.AddConsumerOf<PreInsertEvent<TestInstance>>()
					.UsingConsumer(_preInsert.Complete)
					.HandleOnCallingThread();

				x.AddConsumerOf<PreInsertEvent<PreviousValue>>()
					.UsingConsumer(_preInsertPrevious.Complete)
					.HandleOnCallingThread();
			});

			ExtraConfiguration = cfg =>
			{
				cfg.AddAuditEventListeners(_channel);
			};

			using (ISession session = SessionFactory.OpenSession())
			using (ITransaction transaction = session.BeginTransaction())
			{
				session.CreateQuery("Delete TestInstance").ExecuteUpdate();

				var instance = new TestInstance(27, 123.45m);
				instance.UpdateValueChannel.Send(new UpdateValue(27, 100.0m));

				session.Save(instance);

				transaction.Commit();
			}
		}
Example #34
0
 public void CreateTest(TestInstance Test)
 {
     foreach (RectangleData recData in Test.RectangleList)
         CreateRectangle(recData);
 }
Example #35
0
        public void NextTest()
        {
            if (currentTest > 31)
            {
                Application.Current.Shutdown();
            }
            else
            {
                canvas.Children.Clear();
                Test_One = fileHandler.ReadBinary(currentTest.ToString() + ".dat");
                currentTest++;

                MessageBox.Show(Test_One.Instruction);
                CreateTest(Test_One);
                stopWatch.Reset();
                stopWatch.Start();
            }
        }
Example #36
0
 public TestInstance(TestInstance value)
 {
     this.value = value.value;
 }
Example #37
0
 public void AddToTestInstances(TestInstance testInstance)
 {
     base.AddObject("TestInstances", testInstance);
 }
Example #38
0
 public static TestInstance Add(TestInstance a, TestInstance b)
 {
     return new TestInstance(a.Value + b.Value);
 }
Example #39
0
 public static TestInstance CreateTestInstance(int id, int testStatusID)
 {
     TestInstance testInstance = new TestInstance();
     testInstance.ID = id;
     testInstance.TestStatusID = testStatusID;
     return testInstance;
 }