Beispiel #1
0
        public void TestFeatureSetIsEmpty()
        {
            var module = LoadModuleXml("FeatureSetIsEmpty.xml");

            _assert.NotNull(module.FeatureSet);
            _assert.Empty(module.FeatureSet);
        }
Beispiel #2
0
        public void FactoryInterfaceDoesNotResolveToNull()
        {
            var kernel = CreateKernel();

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

            _assert.NotNull(factory);
        }
Beispiel #3
0
        public void FactoryInterfaceDoesNotResolveToNull()
        {
            var kernel = CreateKernel();

            var factory = kernel.Get <IGenericFactory <Player, DefaultWorld> >();

            _assert.NotNull(factory);
        }
Beispiel #4
0
 /// <summary>
 /// <see cref="IAssert{TAssert}.Current"/>
 /// </summary>
 /// <param name="assert"></param>
 /// <returns></returns>
 public static IAssert <IEnumerable <TAssert> > NotAny <TAssert>(this IAssert <IEnumerable <TAssert> > assert, Func <TAssert, bool> predicate, string message = null)
 {
     assert.NotNull()
     .Then(s => s.Any(predicate))
     .False(message ?? "已存在匹配项");
     return(assert);
 }
Beispiel #5
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);
        }
Beispiel #6
0
        public void ParseExampleCode()
        {
            var parser     = new UnifiedShaderParser();
            var codeStream =
                Assembly.GetExecutingAssembly().GetManifestResourceStream("Protogame.Tests.UnifiedShaderExample.usl");

            _assert.NotNull(codeStream);
            var codeReader = new StreamReader(codeStream);
            var effect     = parser.Parse(codeReader.ReadToEnd());
        }
Beispiel #7
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"));
        }
Beispiel #8
0
        public void TestInstantiateComponentResolution()
        {
            var kernel = new StandardKernel();

            kernel.Load <ProtogameComponentModule>();

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

            factory.HierarchyRoot = new object();
            factory.PlanForEntityCreation <EntityC>();
            var entities = factory.CreateEntities();

            _assert.NotNull(((EntityC)entities[0]).ComponentD);
        }
    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);
    }
Beispiel #10
0
 /// <summary>
 /// <see cref="IAssert{TAssert}.Current"/>不为null
 /// </summary>
 /// <param name="assert"></param>
 /// <returns></returns>
 public static IAssert <TAssert> NotNull <TAssert>(this IAssert <TAssert> assert) where TAssert : class
 {
     return(assert.NotNull($"{assert.Name},不能为null"));
 }
Beispiel #11
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>();
            }
Beispiel #12
0
        public static void SimpleExecute([NotNull] IAssert assert)
        {
            var result = Shell.Execute("curl --version");

            assert.NotNull(result.StdOut);
        }
    public void ReaderHeader_WithPrivateKey()
    {
        using (var options = new SymmetricEncryptionProviderOptions())
            using (var engine = new SymmetricEncryptionProvider())
            {
                byte[] privateKey = null;
                using (var rng = new RandomNumberGenerator())
                {
                    privateKey = rng.NextBytes(20);
                }

                byte[] data    = null;
                var    header1 = engine.GenerateHeader(options, privateKey: privateKey);
                data = new byte[header1.Bytes.Memory.Length];
                header1.Bytes.Memory.CopyTo(data);


                var ms = new MemoryStream(data);
                using (var header = engine.ReadHeader(ms, options, privateKey))
                {
                    ms.Position = 0;

                    var data2 = new byte[header.Bytes.Memory.Length];
                    header.Bytes.Memory.CopyTo(data2);

                    assert.Equal(data.Length, data2.Length);
                    assert.Equal(data, data2);

                    assert.NotNull(header);
                    assert.Equal(1, header.Version);
                    assert.Equal(SymmetricAlgorithmType.AES, header.SymmetricAlgorithmType);
                    assert.Equal(KeyedHashAlgorithmType.HMACSHA256, header.KeyedHashAlgorithmType);
                    assert.Equal(0, header.MetaDataSize);
                    assert.NotEqual(0, header.SigningSaltSize);
                    assert.NotEqual(0, header.SymmetricSaltSize);
                    assert.NotEqual(0, header.IvSize);
                    assert.NotEqual(0, header.HashSize);
                    assert.NotEqual(0, header.Iterations);
                    assert.NotNull(header.SymmetricKey);
                    assert.NotNull(header.IV);
                    assert.NotNull(header.SigningKey);
                    assert.NotNull(header.Bytes);

                    assert.Ok(!header.SymmetricKey.Memory.IsEmpty);
                    assert.Ok(!header.IV.Memory.IsEmpty);
                    assert.Ok(!header.SigningKey.Memory.IsEmpty);

                    var temp = new byte[header.SymmetricKey.Memory.Length];
                    header.SymmetricKey.Memory.CopyTo(temp);
                    assert.NotEqual(privateKey, temp);

                    assert.Ok(!header.Bytes.Memory.IsEmpty);

                    ms.Position = 0;
                    using (var br = new BinaryReader(ms))
                    {
                        assert.Equal(1, br.ReadInt16());
                        assert.Equal((short)SymmetricAlgorithmType.AES, br.ReadInt16());
                        assert.Equal((short)KeyedHashAlgorithmType.HMACSHA256, br.ReadInt16());
                        assert.Equal(header.MetaDataSize, br.ReadInt32());
                        assert.Equal(header.Iterations, br.ReadInt32());
                        assert.Equal(header.SymmetricSaltSize, br.ReadInt16());
                        assert.Equal(header.SigningSaltSize, br.ReadInt16());
                        assert.Equal(header.IvSize, br.ReadInt16());
                        assert.Equal(header.SymmetricKeySize, br.ReadInt16());
                        assert.Equal(header.HashSize, br.ReadInt16());

                        assert.Equal(header.Version, header1.Version);
                        assert.Equal(header.KeyedHashAlgorithmType, header1.KeyedHashAlgorithmType);
                        assert.Equal(header.SymmetricAlgorithmType, header1.SymmetricAlgorithmType);
                        assert.Equal(header.MetaDataSize, header1.MetaDataSize);
                        assert.Equal(header.Iterations, header1.Iterations);
                        assert.Equal(header.SymmetricSaltSize, header1.SymmetricSaltSize);
                        assert.Equal(header.SigningSaltSize, header1.SigningSaltSize);
                        assert.Equal(header.IvSize, header1.IvSize);
                        assert.Equal(header.SymmetricKeySize, header1.SymmetricKeySize);
                        assert.Equal(header.HashSize, header1.HashSize);

                        byte[] metadata      = null;
                        byte[] symmetricSalt = null;
                        byte[] signingSalt   = null;
                        byte[] iv            = null;
                        byte[] symmetricKey  = null;
                        byte[] hash          = null;

                        // header values
                        // 1. version
                        // 2. metadataSize
                        // 3. iterations
                        // 4. symmetricSaltSize
                        // 5. signingSaltSize
                        // 6. ivSize
                        // 7. symmetricKeySize
                        // 8. hashSize

                        // header values
                        // 1. metadata (optional)
                        // 2. symmetricSalt (optional)
                        // 3. signingSalt (optional)
                        // 4. iv
                        // 5. symmetricKey (optional)
                        // 6. hash

                        if (header.MetaDataSize > 0)
                        {
                            metadata = br.ReadBytes(header.MetaDataSize);
                        }

                        if (header.SymmetricSaltSize > 0)
                        {
                            assert.Equal(options.SaltSize / 8, header.SymmetricSaltSize);
                            var name = System.Security.Cryptography.HashAlgorithmName.SHA256;
                            symmetricSalt = br.ReadBytes(header.SymmetricSaltSize);
                            using (var generator = new Rfc2898DeriveBytes(privateKey, symmetricSalt, options.Iterations, name))
                            {
                                symmetricKey = generator.GetBytes(options.KeySize / 8);
                                var p1 = new byte[header.SymmetricKey.Memory.Length];
                                var p2 = new byte[header1.SymmetricKey.Memory.Length];
                                header.SymmetricKey.Memory.CopyTo(p1);
                                header1.SymmetricKey.Memory.CopyTo(p2);
                                assert.Equal(p1, p2);

                                assert.Equal(symmetricKey, p1);
                            }

                            symmetricKey = null;
                        }

                        if (header.SigningSaltSize > 0)
                        {
                            signingSalt = br.ReadBytes(header.SigningSaltSize);
                            var name = System.Security.Cryptography.HashAlgorithmName.SHA256;
                            using (var generator = new Rfc2898DeriveBytes(privateKey, signingSalt, options.Iterations, name))
                            {
                                var signingKey = generator.GetBytes(options.KeySize / 8);
                                var p1         = new byte[header.SymmetricKey.Memory.Length];
                                header.SigningKey.Memory.CopyTo(p1);

                                assert.Equal(signingKey, p1);
                            }
                        }

                        if (header.IvSize > 0)
                        {
                            iv = br.ReadBytes(header.IvSize);

                            var iv2 = new byte[header.IvSize];
                            header.IV.Memory.CopyTo(iv2);
                            assert.Equal(iv, iv2);
                        }

                        if (header.SymmetricKeySize > 0)
                        {
                            symmetricKey = br.ReadBytes(header.SymmetricKeySize);
                        }

                        if (header.HashSize > 0)
                        {
                            hash = br.ReadBytes(header.HashSize);

                            var hash2 = new byte[header.HashSize];
                            header.Hash.Memory.CopyTo(hash2);
                            assert.Equal(hash, hash2);
                        }

                        assert.Null(metadata);
                        assert.NotNull(hash);
                        assert.NotNull(signingSalt);
                        assert.NotNull(symmetricSalt);

                        // header property has a copy but does not
                        // write it to the file header when a private key
                        // is provided.
                        assert.Null(symmetricKey);
                        assert.NotNull(iv);
                        assert.NotEmpty(hash);
                        assert.NotEmpty(signingSalt);
                        assert.NotEmpty(symmetricSalt);

                        assert.NotEmpty(iv);
                    }
                }
            }
    }