Esempio n. 1
0
        public void TestNetworkMessageCanBeSerializedAndDeserialized()
        {
            var kernel = new StandardKernel();

            kernel.Load <ProtogameNetworkModule>();
            kernel.Bind <INetworkMessage>().To <TestNetworkMessage>();

            var serializer = kernel.Get <INetworkMessageSerialization>();
            var message    = new TestNetworkMessage
            {
                TestInteger = 5,
                TestString  = "hello world"
            };
            var  data = serializer.Serialize(message);
            Type messageType;
            var  deserialized = serializer.Deserialize(data, out messageType);

            _assert.Same(messageType, typeof(TestNetworkMessage));
            _assert.NotNull(deserialized);
            _assert.IsType <TestNetworkMessage>(deserialized);

            var content = (TestNetworkMessage)deserialized;

            _assert.Equal(5, content.TestInteger);
            _assert.Equal("hello world", content.TestString);
        }
Esempio n. 2
0
        public void TestFeatureSetIsPackageManagement()
        {
            var module = LoadModuleXml("FeatureSetIsPackageManagement.xml");

            _assert.NotNull(module.FeatureSet);
            _assert.Equal(1, module.FeatureSet.Count);
            _assert.Contains(Feature.PackageManagement, module.FeatureSet);
        }
        private void AssertSphere(double[] a, double[] b, double[] c, double[] d, double[] centre, double radius)
        {
            CircumcentreSolver solver = new CircumcentreSolver(a, b, c, d);

            _assert.Equal(centre[0], solver.Centre[0]);
            _assert.Equal(centre[1], solver.Centre[1]);
            _assert.Equal(centre[2], solver.Centre[2]);
            _assert.Equal(radius, solver.Radius);
        }
Esempio n. 4
0
        public void TestBasicPropagation()
        {
            var @event = new BasicEvent {
                Original = 1
            };
            var binder = new BasicStaticEventBinder();
            var engine = new DefaultEventEngine <IGameContext>(new StandardKernel(), new[] { binder });

            engine.Fire(null, @event);
            _staticAssert.Equal(1, @event.HitValue);
        }
    public void SimpleReader_ListParameters()
    {
        using var sqlite = new Microsoft.Data.Sqlite.SqliteConnection("Data Source=:memory:");
        using var conn   = new DataConnection(sqlite, new DataSqlDialect());

        conn.Open();
        assert.Equal(ConnectionState.Open, conn.State);

        var query  = conn.SqlDialect.CreateBuilder();
        var reader = conn.ExecuteReader(
            query.Append("SELECT ? AS first"), new List <object>()
        {
            "one"
        });

        bool read = false;

        while (reader.Read())
        {
            var v = reader.GetString("first");
            assert.Equal("one", v);

            read = true;
        }

        assert.Ok(read);
    }
        public void GenerationIsCorrect()
        {
            this.SetupTest("ModuleInfoGetsUpgraded");

            if (File.Exists(GetPath(Path.Combine("Build", "Module.xml"))))
            {
                File.Delete(GetPath(Path.Combine("Build", "Module.xml")));
            }

            File.Copy(
                GetPath(Path.Combine("Build", "ModuleUnconverted.xml")),
                GetPath(Path.Combine("Build", "Module.xml")));

            this.Generate("Windows");

            _assert.True(File.Exists(GetPath(Path.Combine("Build", "Module.xml"))));
            _assert.Equal(@"<?xml version=""1.0"" encoding=""utf-8""?>
<Module>
  <Name>Protobuild</Name>
  <DefaultAction>resync</DefaultAction>
  <GenerateNuGetRepositories>true</GenerateNuGetRepositories>
  <Packages>
    <Package Uri=""http://protobuild.org/hach-que/xunit"" Folder=""xunit"" GitRef=""master"" />
  </Packages>
</Module>".Replace("\r\n", "\n"), ReadFile(Path.Combine("Build", "Module.xml")).Trim().Replace("\r\n", "\n"));
        }
Esempio n. 7
0
        public static void Grow(IAssert assert)
        {
            var list = System.Array.Empty <string>();

            assert.Check().Equal(0, list.Length);
            list = list.Grow(10);

            assert.Equal(10, list.Length);
        }
Esempio n. 8
0
        public static void Shrink(IAssert assert)
        {
            var list = new string[10];

            assert.Check().Equal(10, list.Length);
            list = list.Shrink(2);

            assert.Equal(8, list.Length);
        }
Esempio n. 9
0
        public void PackageIsCorrect()
        {
            this.SetupTest("PackageFilterCorrect", isPackTest: true);

            this.OtherMode("pack", args: ". Windows.tar.lzma Windows Build/Publish/Filter.Windows.txt", purge: false);

            var packagedFiles = this.LoadPackage("Windows.tar.lzma");

            _assert.Contains("Build/", packagedFiles.Keys);
            _assert.Contains("Build/Module.xml", packagedFiles.Keys);
            _assert.Contains("Build/Projects/", packagedFiles.Keys);
            _assert.Contains("Build/Projects/Console.Windows.definition", packagedFiles.Keys);
            _assert.Contains("Console/", packagedFiles.Keys);
            _assert.Contains("Console/Program.cs", packagedFiles.Keys);
            _assert.Equal(6, packagedFiles.Count);

            using (var stream = new MemoryStream(packagedFiles["Build/Projects/Console.Windows.definition"]))
            {
                using (var reader = new StreamReader(stream))
                {
                    _assert.Contains("WINDOWS", reader.ReadToEnd());
                }
            }

            this.OtherMode("pack", args: ". Linux.tar.lzma Linux Build/Publish/Filter.Linux.txt", purge: false);

            packagedFiles = this.LoadPackage("Linux.tar.lzma");

            _assert.Contains("Build/", packagedFiles.Keys);
            _assert.Contains("Build/Module.xml", packagedFiles.Keys);
            _assert.Contains("Build/Projects/", packagedFiles.Keys);
            _assert.Contains("Build/Projects/Console.Linux.definition", packagedFiles.Keys);
            _assert.Contains("Console/", packagedFiles.Keys);
            _assert.Contains("Console/Program.cs", packagedFiles.Keys);
            _assert.Equal(6, packagedFiles.Count);

            using (var stream = new MemoryStream(packagedFiles["Build/Projects/Console.Linux.definition"]))
            {
                using (var reader = new StreamReader(stream))
                {
                    _assert.Contains("LINUX", reader.ReadToEnd());
                }
            }
        }
Esempio n. 10
0
        public static void PowerShellHelloWorld([NotNull] IAssert assert)
        {
            var pwsh   = new PowerShell();
            var result = (ShellCaptureResult)pwsh.ExecCommand("Write-Host 'Hello World'");

            assert.NotNull(result);
            assert.Equal(0, result.ExitCode);
            var firstLine = result.StdOut.FirstOrDefault();

            assert.NotEmpty(firstLine);
            assert.True(firstLine.Contains("Hello World"));
        }
Esempio n. 11
0
        public void Scenario01()
        {
            var request = new RequestModel()
            {
                BaseUrl    = "http://localhost:3000",
                HttpMethod = "get",
                Resource   = "users/1"
            };
            var response = _client.Invoke(request);

            _logger.LogInformation("Execute Scenario01");
            _assert.Equal(1, 1);
        }
Esempio n. 12
0
        public void GeneratedFactoryCanSpawn()
        {
            var kernel = CreateKernel();

            var factory = kernel.Get <IEntityFactory>();

            _assert.NotNull(factory);

            var player = factory.CreatePlayer("test");

            _assert.NotNull(player);
            _assert.Equal("test", player.Name);
        }
        public void PackageIsCorrect()
        {
            this.SetupTest("PackageFilterCorrectModuleXml", isPackTest: true);

            this.OtherMode("pack", args: ". Windows.tar.lzma Windows Filter.Windows.txt", purge: false);

            var packagedFiles = this.LoadPackage("Windows.tar.lzma");

            _assert.Contains("Build/", packagedFiles.Keys);
            _assert.Contains("Build/Module.xml", packagedFiles.Keys);
            _assert.Contains("Build/Projects/", packagedFiles.Keys);
            _assert.Contains("Build/Projects/Console.definition", packagedFiles.Keys);
            _assert.Equal(4, packagedFiles.Count);
        }
Esempio n. 14
0
        public void PackageIsCorrect()
        {
            this.SetupTest("PackageEverythingCorrectGZip", isPackTest: true);

            this.OtherMode("pack", args: "Publish Test.tar.gz Windows Filter.txt --format tar/gzip", purge: false);

            var packagedFiles = this.LoadPackage("Test.tar.gz");

            _assert.Contains("Build/", packagedFiles.Keys);
            _assert.Contains("Build/Module.xml", packagedFiles.Keys);
            _assert.Contains("Build/Projects/", packagedFiles.Keys);
            _assert.Contains("Build/Projects/Console.definition", packagedFiles.Keys);
            _assert.Contains("Console/", packagedFiles.Keys);
            _assert.Contains("Console/Program.cs", packagedFiles.Keys);
            _assert.Equal(6, packagedFiles.Count);
        }
Esempio n. 15
0
        public void GenerationIsCorrect()
        {
            this.SetupTest("PackageResolutionDoesNotOccurInSubmodulesTwice");

            var src = this.SetupSrcPackage();

            try
            {
                // Make sure the Package directory is removed so we have a clean test every time.
                if (Directory.Exists(this.GetPath("Package")))
                {
                    PathUtils.AggressiveDirectoryDelete(this.GetPath("Package"));
                }

                var platform = "Windows";
                if (Path.DirectorySeparatorChar == '/')
                {
                    platform = "Linux";

                    if (Directory.Exists("/Library"))
                    {
                        platform = "MacOS";
                    }
                }

                var stdout = this.Generate(
                    platform: platform,
                    args: "--redirect http://protobuild.org/hach-que/TestEmptyPackage local-git://" + src,
                    capture: true).Item1;

                var idxSubmoduleGeneration = stdout.IndexOf("Invoking submodule generation for Submodule",
                                                            System.StringComparison.InvariantCulture);
                _assert.NotEqual(-1, idxSubmoduleGeneration);

                var substrStdout         = stdout.Substring(idxSubmoduleGeneration);
                var idxPackageResolution =
                    substrStdout.IndexOf("Starting resolution of packages for " + platform + "...",
                                         System.StringComparison.InvariantCulture);

                // We should not see any package resolution we invoke submodule generation.
                _assert.Equal(-1, idxPackageResolution);
            }
            finally
            {
                PathUtils.AggressiveDirectoryDelete(src);
            }
        }
Esempio n. 16
0
            public RenderPipelineWorld(IAssetManagerProvider assetManagerProvider, I2DRenderUtilities renderUtilities, IGraphicsFactory graphicsFactory, IAssert assert)
            {
                _renderUtilities          = renderUtilities;
                _assert                   = assert;
                _texture                  = assetManagerProvider.GetAssetManager().Get <TextureAsset>("texture.Player");
                _invertPostProcess        = graphicsFactory.CreateInvertPostProcessingRenderPass();
                _blurPostProcess          = graphicsFactory.CreateBlurPostProcessingRenderPass();
                _customPostProcess        = graphicsFactory.CreateCustomPostProcessingRenderPass("effect.MakeRed");
                _captureInlinePostProcess = graphicsFactory.CreateCaptureInlinePostProcessingRenderPass();
                _captureInlinePostProcess.RenderPipelineStateAvailable = d =>
                {
#if MANUAL_TEST
#elif RECORDING
                    using (var writer = new StreamWriter("output" + _frame + ".png"))
                    {
                        d.SaveAsPng(writer.BaseStream, Width, Height);
                    }
#else
                    var baseStream =
                        typeof(RenderPipelineWorld).Assembly.GetManifestResourceStream(
                            "Protogame.Tests.Expected.RenderPipeline.output" + _frame + ".png");
                    var baseBytes = new byte[baseStream.Length];
                    baseStream.Read(baseBytes, 0, baseBytes.Length);
                    var memoryStream = new MemoryStream();
                    d.SaveAsPng(memoryStream, Width, Height);
                    var memoryBytes = new byte[memoryStream.Position];
                    memoryStream.Seek(0, SeekOrigin.Begin);
                    memoryStream.Read(memoryBytes, 0, memoryBytes.Length);
                    memoryStream.Dispose();
                    baseStream.Dispose();

                    _assert.Equal(baseBytes, memoryBytes);
#endif

#if MANUAL_TEST
                    _manualTest++;
                    if (_manualTest % 60 == 0)
                    {
                        _frame++;
                    }
#else
                    _frame++;
#endif
                };

                this.Entities = new List <IEntity>();
            }
Esempio n. 17
0
        public void TestSetAndGet()
        {
            var octree = new PositionOctree <string>();

            octree.Insert("hello", 0, 0, 0);
            _assert.Equal("hello", octree.Find(0, 0, 0));
            octree.Insert("world", -1, -1, -1);
            _assert.Equal("world", octree.Find(-1, -1, -1));
            octree.Insert("blah", -1, 0, -1);
            _assert.Equal("blah", octree.Find(-1, 0, -1));
        }
Esempio n. 18
0
        public void CommandLineToPassToSubmoduleIsEmptyWhenFeaturesAreNotSpecifiedOnCommandLine()
        {
            var kernel = GetKernel();

            var featureManager = kernel.Get <IFeatureManager>();

            featureManager.LoadFeaturesFromCommandLine(null);
            featureManager.LoadFeaturesFromSpecificModule(new ModuleInfo
            {
                FeatureSet = new List <Feature>()
            });

            var module    = new ModuleInfo();
            var submodule = new ModuleInfo();

            _assert.Equal("--features \"\" ", featureManager.GetFeatureArgumentToPassToSubmodule(module, submodule));
        }
Esempio n. 19
0
        public void GenerationIsCorrect()
        {
            this.SetupTest("QueryFeatures");

            var featureList         = this.OtherMode("query-features", capture: true).Item1.Split(new[] { '\n' }, System.StringSplitOptions.RemoveEmptyEntries);
            var expectedFeatureList = new[] {
                "query-features",
                "no-resolve",
                "list-packages",
                "skip-invocation-on-no-standard-projects",
                "skip-synchronisation-on-no-standard-projects",
                "skip-resolution-on-no-packages-or-submodules",
                "inline-invocation-if-identical-hashed-executables",
                "no-host-generate",
                "propagate-features",
            };

            _assert.Equal(expectedFeatureList, featureList);
        }
Esempio n. 20
0
        public void TestIntArray()
        {
            var poolManager = new DefaultPoolManager();

            var pool = poolManager.NewArrayPool <int>("testintarray", 5, 10, x => { });

            _assert.Equal(5, pool.Free);
            _assert.Equal(0, pool.NextAvailable);
            _assert.Equal(-1, pool.NextReturn);

            var a1 = pool.Get();

            _assert.Equal(4, pool.Free);
            _assert.Equal(1, pool.NextAvailable);
            _assert.Equal(0, pool.NextReturn);

            var a2 = pool.Get();

            _assert.Equal(3, pool.Free);
            _assert.Equal(2, pool.NextAvailable);
            _assert.Equal(0, pool.NextReturn);

            var a3 = pool.Get();

            _assert.Equal(2, pool.Free);
            _assert.Equal(3, pool.NextAvailable);
            _assert.Equal(0, pool.NextReturn);

            var a4 = pool.Get();

            _assert.Equal(1, pool.Free);
            _assert.Equal(4, pool.NextAvailable);
            _assert.Equal(0, pool.NextReturn);

            var a5 = pool.Get();

            _assert.Equal(0, pool.Free);
            _assert.Equal(-1, pool.NextAvailable);
            _assert.Equal(0, pool.NextReturn);

            // Ensure instances are unique.
            _assert.NotSame(a1, a2);
            _assert.NotSame(a1, a3);
            _assert.NotSame(a1, a4);
            _assert.NotSame(a1, a5);
            _assert.NotSame(a2, a3);
            _assert.NotSame(a2, a4);
            _assert.NotSame(a2, a5);
            _assert.NotSame(a3, a4);
            _assert.NotSame(a3, a5);
            _assert.NotSame(a4, a5);

            // Test release
            pool.Release(a3);

            _assert.Equal(1, pool.Free);
            _assert.Equal(0, pool.NextAvailable);
            _assert.Equal(1, pool.NextReturn);

            pool.Release(a4);

            _assert.Equal(2, pool.Free);
            _assert.Equal(0, pool.NextAvailable);
            _assert.Equal(2, pool.NextReturn);

            var b3 = pool.Get();

            _assert.Equal(1, pool.Free);
            _assert.Equal(1, pool.NextAvailable);
            _assert.Equal(2, pool.NextReturn);

            var b4 = pool.Get();

            _assert.Equal(0, pool.Free);
            _assert.Equal(-1, pool.NextAvailable);
            _assert.Equal(2, pool.NextReturn);

            // Check same instances
            _assert.Same(a3, b3);
            _assert.Same(a4, b4);

            // Check offset release
            pool.Release(a1);

            _assert.Equal(1, pool.Free);
            _assert.Equal(2, pool.NextAvailable);
            _assert.Equal(3, pool.NextReturn);

            pool.Release(a2);

            _assert.Equal(2, pool.Free);
            _assert.Equal(2, pool.NextAvailable);
            _assert.Equal(4, pool.NextReturn);

            pool.Release(b3);

            _assert.Equal(3, pool.Free);
            _assert.Equal(2, pool.NextAvailable);
            _assert.Equal(0, pool.NextReturn);

            pool.Release(b4);

            _assert.Equal(4, pool.Free);
            _assert.Equal(2, pool.NextAvailable);
            _assert.Equal(1, pool.NextReturn);

            pool.Release(a5);

            _assert.Equal(5, pool.Free);
            _assert.Equal(2, pool.NextAvailable);
            _assert.Equal(-1, pool.NextReturn);

            // Check offset get
            var c1 = pool.Get();

            _assert.Equal(4, pool.Free);
            _assert.Equal(3, pool.NextAvailable);
            _assert.Equal(2, pool.NextReturn);

            var c2 = pool.Get();

            _assert.Equal(3, pool.Free);
            _assert.Equal(4, pool.NextAvailable);
            _assert.Equal(2, pool.NextReturn);

            var c3 = pool.Get();

            _assert.Equal(2, pool.Free);
            _assert.Equal(0, pool.NextAvailable);
            _assert.Equal(2, pool.NextReturn);

            var c4 = pool.Get();

            _assert.Equal(1, pool.Free);
            _assert.Equal(1, pool.NextAvailable);
            _assert.Equal(2, pool.NextReturn);

            var c5 = pool.Get();

            _assert.Equal(0, pool.Free);
            _assert.Equal(-1, pool.NextAvailable);
            _assert.Equal(2, pool.NextReturn);

            // Make sure reallocation got the right instances
            _assert.Same(a1, c1);
            _assert.Same(a2, c2);
            _assert.Same(a3, c3);
            _assert.Same(a4, c4);
            _assert.Same(a5, c5);
        }
Esempio n. 21
0
    public void Ctor()
    {
        using var fake = new FakeDbConnection();
        using var conn = new DataConnection(fake, new DataSqlDialect());

        assert.Equal(ConnectionState.Closed, conn.State);
        assert.Null(conn.ConnectionString);
        assert.NotNull(conn.SqlDialect);
        assert.Equal("Sqlite", conn.Provider);
    }
Esempio n. 22
0
 /// <summary>
 /// Verifies that two strings are equal.
 /// </summary>
 /// <param name="expected">The expected string value.</param>
 /// <param name="actual">The actual string value.</param>
 /// <exception cref="EqualException">Thrown when the strings are not equivalent.</exception>
 public static void Equal(this IAssert assert, string expected, string actual)
 {
     assert.Equal(expected, actual, ignoreCase: false, ignoreLineEndingDifferences: false, ignoreWhiteSpaceDifferences: false);
 }
        public void WriteFrameworksAreCorrect()
        {
            var kernel = GetKernel();

            var platformMapping  = kernel.Get <INuGetPlatformMapping>();
            var workingDirectory = Environment.CurrentDirectory;

            _assert.Equal("monoandroid", platformMapping.GetFrameworkNameForWrite(workingDirectory, "Android"));
            _assert.Equal("xamarinios", platformMapping.GetFrameworkNameForWrite(workingDirectory, "iOS"));
            _assert.Equal("xamarintvos", platformMapping.GetFrameworkNameForWrite(workingDirectory, "tvOS"));
            _assert.Equal("mono40", platformMapping.GetFrameworkNameForWrite(workingDirectory, "Linux"));
            _assert.Equal("xamarinmac", platformMapping.GetFrameworkNameForWrite(workingDirectory, "MacOS"));
            _assert.Equal("monoandroid", platformMapping.GetFrameworkNameForWrite(workingDirectory, "Ouya"));
            _assert.Equal("netstandard1.1", platformMapping.GetFrameworkNameForWrite(workingDirectory, "PCL"));
            _assert.Equal("net45", platformMapping.GetFrameworkNameForWrite(workingDirectory, "Windows"));
            _assert.Equal("win8", platformMapping.GetFrameworkNameForWrite(workingDirectory, "Windows8"));
            _assert.Equal("wp8", platformMapping.GetFrameworkNameForWrite(workingDirectory, "WindowsPhone"));
            _assert.Equal("wp81", platformMapping.GetFrameworkNameForWrite(workingDirectory, "WindowsPhone81"));
            _assert.Equal("uap", platformMapping.GetFrameworkNameForWrite(workingDirectory, "WindowsUniversal"));
            _assert.Equal("net35", platformMapping.GetFrameworkNameForWrite(workingDirectory, "Unity"));
        }
        public void SpeedIsNotClampedWhenSpeedIsZero()
        {
            var kernel = new StandardKernel();

            kernel.Load <ProtogameCoreModule>();
            kernel.Load <ProtogamePlatformingIoCModule>();
            var platforming = kernel.Get <IPlatforming>();

            var boundingBox = this.CreateBoundingBox(0, 0, 0, 0, 0, 0);

            platforming.ClampSpeed(boundingBox, 10, 10);
            _assert.Equal(0, boundingBox.XSpeed);
            _assert.Equal(0, boundingBox.YSpeed);
        }
Esempio n. 25
0
        public void TestPickKeys()
        {
            var machine = new SingleTimeMachine(100);
            var list    = new List <int>();

            list.Add(5);
            list.Add(10);
            list.Add(15);
            list.Add(20);
            list.Add(25);
            list.Add(30);
            list.Add(35);
            list.Add(40);
            list.Add(45);
            list.Add(50);

            int previous, next;

            machine.FindSurroundingTickValues(list, 32, out previous, out next);
            _assert.Equal(5, previous);
            _assert.Equal(6, next);

            machine.FindSurroundingTickValues(list, 16, out previous, out next);
            _assert.Equal(2, previous);
            _assert.Equal(3, next);

            machine.FindSurroundingTickValues(list, 2, out previous, out next);
            _assert.Equal(-1, previous);
            _assert.Equal(0, next);

            machine.FindSurroundingTickValues(list, 6, out previous, out next);
            _assert.Equal(0, previous);
            _assert.Equal(1, next);

            machine.FindSurroundingTickValues(list, 11, out previous, out next);
            _assert.Equal(1, previous);
            _assert.Equal(2, next);

            machine.FindSurroundingTickValues(list, 52, out previous, out next);
            _assert.Equal(9, previous);
            _assert.Equal(-1, next);

            machine.FindSurroundingTickValues(list, 0, out previous, out next);
            _assert.Equal(-1, previous);
            _assert.Equal(0, next);

            for (var i = 0; i < list.Count; i++)
            {
                machine.FindSurroundingTickValues(list, (i + 1) * 5, out previous, out next);
                _assert.Equal(i, previous);
                _assert.Equal(i, next);
            }

            for (var i = 0; i < list.Count - 1; i++)
            {
                machine.FindSurroundingTickValues(list, ((i + 1) * 5) + 1, out previous, out next);
                _assert.Equal(i, previous);
                _assert.Equal(i + 1, next);
            }

            for (var i = 1; i < list.Count; i++)
            {
                machine.FindSurroundingTickValues(list, ((i + 1) * 5) - 1, out previous, out next);
                _assert.Equal(i - 1, previous);
                _assert.Equal(i, next);
            }
        }
Esempio n. 26
0
        // We use file:// explicitly in these tests so that they work
        // on all platforms.  These tests also pass on Windows if the
        // paths are of "C:\path\to\module\" form, and also pass on UNIX
        // if they are of the "/path/to/module/" form.

        public void DirectoriesNextToEachOther()
        {
            _assert.Equal(
                "..\\target\\",
                PathUtils.GetRelativePath("file:///path/to/module/", "file:///path/to/target/"));
        }
Esempio n. 27
0
            public RenderPipelineWorld(
                IAssetManager assetManager,
                I2DRenderUtilities renderUtilities,
                IGraphicsFactory graphicsFactory,
                IAssert assert,
                ITestAttachment testAttachment,
                IRenderTargetBackBufferUtilities renderTargetBackBufferUtilities,
                IGraphicsBlit graphicsBlit)
            {
                _renderUtilities                 = renderUtilities;
                _assert                          = assert;
                _testAttachment                  = testAttachment;
                _texture                         = assetManager.Get <TextureAsset>("texture.Player");
                _invertPostProcess               = graphicsFactory.CreateInvertPostProcessingRenderPass();
                _blurPostProcess                 = graphicsFactory.CreateBlurPostProcessingRenderPass();
                _customPostProcess               = graphicsFactory.CreateCustomPostProcessingRenderPass("effect.MakeRed");
                _captureInlinePostProcess        = graphicsFactory.CreateCaptureInlinePostProcessingRenderPass();
                _renderTargetBackBufferUtilities = renderTargetBackBufferUtilities;
                _graphicsBlit                    = graphicsBlit;
                _captureInlinePostProcess.RenderPipelineStateAvailable = (gameContext, renderContext, previousPass, d) =>
                {
                    if (!_isValidRun)
                    {
                        return;
                    }

                    _renderTarget = _renderTargetBackBufferUtilities.UpdateCustomRenderTarget(_renderTarget, renderContext, SurfaceFormat.Color, DepthFormat.None, 1);

                    // Blit to the capture target.
                    _graphicsBlit.Blit(renderContext, d, _renderTarget);

#if MANUAL_TEST
#elif RECORDING
                    using (var writer = new StreamWriter("output" + _frame + ".png"))
                    {
                        _renderTarget.SaveAsPng(writer.BaseStream, Width, Height);
                    }
#else
                    var baseStream =
                        typeof(RenderPipelineWorld).Assembly.GetManifestResourceStream(
                            "Protogame.Tests.Expected.RenderPipeline.output" + _frame + ".png");
                    _assert.NotNull(baseStream);
                    var memoryStream = new MemoryStream();
                    _renderTarget.SaveAsPng(memoryStream, Width, Height);
                    // ReSharper disable once AssignNullToNotNullAttribute
                    var expected = new Bitmap(baseStream);
                    var actual   = new Bitmap(memoryStream);

                    _assert.Equal(expected.Height, actual.Height);
                    _assert.Equal(expected.Width, actual.Width);
                    var totalPixelValues     = 0L;
                    var incorrectPixelValues = 0L;
                    for (var x = 0; x < expected.Width; x++)
                    {
                        for (var y = 0; y < expected.Height; y++)
                        {
                            var expectedPixel = expected.GetPixel(x, y);
                            var actualPixel   = actual.GetPixel(x, y);

                            totalPixelValues += 255 * 4;

                            if (expectedPixel != actualPixel)
                            {
                                var diffA = System.Math.Abs((int)actualPixel.A - (int)expectedPixel.A);
                                var diffR = System.Math.Abs((int)actualPixel.R - (int)expectedPixel.R);
                                var diffG = System.Math.Abs((int)actualPixel.G - (int)expectedPixel.G);
                                var diffB = System.Math.Abs((int)actualPixel.B - (int)expectedPixel.B);

                                incorrectPixelValues += (diffA + diffR + diffG + diffB);
                            }
                        }
                    }

                    var percentage = (100 - ((incorrectPixelValues / (double)totalPixelValues) * 100f));

                    var combination = _combinations[_frame % _combinations.Count];
                    _testAttachment.Attach("name-" + combination.Id, combination.Name);
                    _testAttachment.Attach("expected-" + combination.Id, baseStream);
                    _testAttachment.Attach("actual-" + combination.Id, memoryStream);
                    _testAttachment.Attach("threshold-" + combination.Id, 99.9);
                    _testAttachment.Attach("measured-" + combination.Id, percentage);

                    if (percentage <= 99.9f)
                    {
                        combination.FailureMessage = "The actual rendered image did not match the expected image close enough (99.9%).";
                    }

                    //memoryStream.Dispose();
                    //baseStream.Dispose();
#endif

#if MANUAL_TEST
                    _manualTest++;
                    if (_manualTest % 60 == 0)
                    {
                        _frame++;
                    }
#else
                    _frame++;
#endif
                };

                this.Entities = new List <IEntity>();
            }
    public void Temp()
    {
        ReadOnlySpan <byte> privateKey = null;
        ReadOnlySpan <byte> salt       = null;

        using (var rng = new RandomNumberGenerator())
        {
            privateKey = rng.NextBytes(20);
            salt       = rng.NextBytes(64 / 8);
        }

        var name = System.Security.Cryptography.HashAlgorithmName.SHA256;

        byte[] pw1 = null;
        byte[] pw2 = null;
        using (var generator = new Rfc2898DeriveBytes(privateKey, salt, 100, name))
        {
            pw1 = generator.GetBytes(256 / 8);
        }

        using (var generator = new Rfc2898DeriveBytes(privateKey, salt, 100, name))
        {
            // assert.Equal(salt, generator.Salt);
            pw2 = generator.GetBytes(256 / 8);
        }

        assert.Equal(pw1, pw2);
    }
Esempio n. 29
0
        public void LocalTemplateSchemeResolvesToCorrectProtocol()
        {
            var packageLookup = GetPackageLookup();

            var metadata = packageLookup.Lookup(new PackageRequestRef("local-template://C:\\Some\\Path", "master", "Windows", false));

            _assert.IsType <FolderPackageMetadata>(metadata);

            var folderMetadata = (FolderPackageMetadata)metadata;

            _assert.Equal("C:\\Some\\Path", folderMetadata.Folder);
            _assert.Equal(PackageManager.PACKAGE_TYPE_TEMPLATE, folderMetadata.PackageType);
        }
Esempio n. 30
0
        /// <summary>
        /// Test that large amounts of data can be sent over the reliable connection
        /// without data becoming corrupt or lost.
        /// </summary>
        public void TestLargeReliableData()
        {
            const string Text = @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Sed id enim et est aliquet mollis. Suspendisse tempus libero in mauris 
iaculis interdum. Ut quis purus in libero euismod suscipit a non est. 
Vestibulum nec scelerisque tellus. Nullam porttitor, metus vitae placerat 
dignissim, nibh ante vehicula felis, vestibulum commodo dui urna sed enim. 
Fusce id neque non neque pellentesque tincidunt. In vehicula lacus vitae nibh 
iaculis scelerisque. Ut libero felis, aliquet nec fringilla sit amet, dignissim
sed quam. Ut a pulvinar quam. Proin mollis dictum ante vel elementum. Sed 
elementum neque libero, ac hendrerit ante semper at. Donec pretium hendrerit 
nisl, non dapibus urna. Phasellus et suscipit nibh, sed tempus magna. Aliquam 
porttitor malesuada ligula, a posuere enim pellentesque quis.

Proin id neque varius, porta eros eget, pellentesque massa. Suspendisse viverra
ligula at lorem dignissim fringilla. Proin viverra nunc neque, nec dignissim 
velit viverra vitae. Vestibulum fringilla eget nunc id cursus cras amet.";

            var udpClient1 = new UdpClient(0);
            var udpClient2 = new UdpClient(0);

            var dispatcher1 = new MxDispatcher(udpClient1);
            var dispatcher2 = new MxDispatcher(udpClient2);

            var port1 = ((IPEndPoint)udpClient1.Client.LocalEndPoint).Port;
            var port2 = ((IPEndPoint)udpClient2.Client.LocalEndPoint).Port;

            try
            {
                string receivedText = null;

                dispatcher1.MessageReceived +=
                    (sender, args) => { receivedText = Encoding.ASCII.GetString(args.Payload); };

                var client      = dispatcher2.Connect(new IPEndPoint(IPAddress.Loopback, port1));
                var clientGroup = dispatcher2.PlaceInGroup(client, "Group2");

                this.SimulateNetworkCycles(4, dispatcher1, dispatcher2);

                dispatcher2.Send(
                    clientGroup,
                    Encoding.ASCII.GetBytes(Text),
                    true);

                _assert.Null(receivedText);

                this.SimulateNetworkCycles(14, dispatcher1, dispatcher2);

                _assert.Equal(Text, receivedText);
            }
            finally
            {
                dispatcher1.Close();
                dispatcher2.Close();
            }
        }