public void MockedTestForTryValidateAllBoundModesWithDefaultParametersShouldPass()
        {
            var settings = new NinjaCoreSettings();

            // Iterate through all BoundsMode values.
            foreach (var boundsMode in BoundsModes)
            {
                // Default Ninja Bounds Settings.
                settings.BoundsMode = boundsMode;
                // Test Multi Value List Scenario With Default Parameters .
                var value = new List <int> {
                    0, int.MaxValue, int.MinValue, int.MaxValue, 0
                };
                var bounds = value.TryValidateBounds(settings: settings);
                bounds.Should().BeOfType <Bounds>();
                bounds.Should().NotBeNull();
                bounds.IsValid.Should().BeTrue();
                bounds.IntendedSkip.Should().Be(0);
                bounds.IntendedTake.Should().Be(value.Count);
                var bytes         = value.ToByteArray(settings: settings);
                var expectedBytes = bytes.ToCharacterArray(Encoding.Unicode).ToByteArray(Encoding.Unicode);
                bytes.Should().BeOfType <byte[]>();
                bytes.Should().NotBeNullOrEmpty();
                bytes.Should().BeEquivalentTo(expectedBytes);
                // Test Null List Scenario With Default Parameters.
                bounds = ((List <int>)null).TryValidateBounds(settings: settings);
                bounds.IsValid.Should().BeTrue();
                bounds.IntendedSkip.Should().Be(0);
                bounds.IntendedTake.Should().Be(0);
                bytes         = ((List <int>)null).ToByteArray(settings: settings);
                expectedBytes = bytes.ToCharacterArray(Encoding.Unicode).ToByteArray(Encoding.Unicode);
                bytes.Should().BeNull();
                bytes.Should().BeEquivalentTo(expectedBytes);
                // Test Empty List Scenario With Default Parameters.
                value  = new List <int>();
                bounds = value.TryValidateBounds(settings: settings);
                bounds.IsValid.Should().BeTrue();
                bounds.IntendedSkip.Should().Be(0);
                bounds.IntendedTake.Should().Be(0);
                bytes         = value.ToByteArray(settings: settings);
                expectedBytes = bytes.ToCharacterArray(Encoding.Unicode).ToByteArray(Encoding.Unicode);
                bytes.Should().BeOfType <byte[]>();
                bytes.Should().BeNullOrEmpty();
                bytes.Should().BeEquivalentTo(expectedBytes);
                // Test Single Value List Scenario With Default Parameters.
                value = new List <int> {
                    int.MinValue
                };
                bounds = value.TryValidateBounds(settings: settings);
                bounds.IsValid.Should().BeTrue();
                bounds.IntendedSkip.Should().Be(0);
                bounds.IntendedTake.Should().Be(1);
                bytes         = value.ToByteArray(settings: settings);
                expectedBytes = bytes.ToCharacterArray(Encoding.Unicode).ToByteArray(Encoding.Unicode);
                bytes.Should().BeOfType <byte[]>();
                bytes.Should().NotBeNullOrEmpty();
                bytes.Should().BeEquivalentTo(expectedBytes);
            }
        }
Example #2
0
        public void MockedTestForTryValidateAllBoundModesWithDefaultParametersShouldPass()
        {
            var settings = new NinjaCoreSettings();

            // Iterate through all BoundsMode values.
            foreach (var boundsMode in BoundsModes)
            {
                // Default Ninja Bounds Settings.
                settings.BoundsMode = boundsMode;
                // Test Multi Value List Scenario With Default Parameters .
                var value = Encoding.UTF8.GetBytes("0123456789");
                value.Should().BeOfType <byte[]>();
                var bounds = value.TryValidateBounds(settings: settings);
                bounds.Should().BeOfType <Bounds>();
                bounds.Should().NotBeNull();
                bounds.IsValid.Should().BeTrue();
                bounds.IntendedSkip.Should().Be(0);
                bounds.IntendedTake.Should().Be(value.Length);
                var bytes         = value.ToByteArray(settings: settings);
                var expectedBytes = bytes.ToCharacterArray(Encoding.UTF8).ToByteArray(Encoding.UTF8);
                bytes.Should().BeOfType <byte[]>();
                bytes.Should().NotBeNullOrEmpty();
                bytes.Should().BeEquivalentTo(expectedBytes);
                // Test Null List Scenario With Default Parameters.
                bounds = ((byte[])null).TryValidateBounds(settings: settings);
                bounds.IsValid.Should().BeTrue();
                bounds.IntendedSkip.Should().Be(0);
                bounds.IntendedTake.Should().Be(0);
                bytes         = ((byte[])null).ToByteArray(settings: settings);
                expectedBytes = bytes.ToCharacterArray(Encoding.UTF8).ToByteArray(Encoding.UTF8);
                bytes.Should().BeNull();
                bytes.Should().BeEquivalentTo(expectedBytes);
                // Test Empty List Scenario With Default Parameters.
                value  = new byte[0];
                bounds = value.TryValidateBounds(settings: settings);
                bounds.IsValid.Should().BeTrue();
                bounds.IntendedSkip.Should().Be(0);
                bounds.IntendedTake.Should().Be(0);
                bytes         = value.ToByteArray(settings: settings);
                expectedBytes = bytes.ToCharacterArray(Encoding.UTF8).ToByteArray(Encoding.UTF8);
                bytes.Should().BeOfType <byte[]>();
                bytes.Should().BeNullOrEmpty();
                bytes.Should().BeEquivalentTo(expectedBytes);
                // Test Single Value List Scenario With Default Parameters.
                value  = new byte[] { 0x01 };
                bounds = value.TryValidateBounds(settings: settings);
                bounds.IsValid.Should().BeTrue();
                bounds.IntendedSkip.Should().Be(0);
                bounds.IntendedTake.Should().Be(1);
                bytes         = value.ToByteArray(settings: settings);
                expectedBytes = bytes.ToCharacterArray(Encoding.UTF8).ToByteArray(Encoding.UTF8);
                bytes.Should().BeOfType <byte[]>();
                bytes.Should().NotBeNullOrEmpty();
                bytes.Should().BeEquivalentTo(expectedBytes);
            }
        }
        public void MockedTestForTryClearAllBoundModesShouldPass()
        {
            var settings = new NinjaCoreSettings();

            // Iterate through all BoundsMode values.
            foreach (var boundsMode in BoundsModes)
            {
                // Default Ninja Bounds Settings.
                NinjaCoreSettings.DefaultBoundsMode = boundsMode;

                var value = Encoding.UTF8.GetBytes("0123456789").ToList();
                value.Should().BeOfType <List <byte> >();
                value.Should().NotBeNullOrEmpty();

                var partialClear = Encoding.UTF8.GetBytes("012345\0\089").ToList();
                partialClear.Should().BeOfType <List <byte> >();
                partialClear.Should().NotBeNullOrEmpty();

                var fullClear = Encoding.UTF8.GetBytes("\0\0\0\0\0\0\0\0\0\0").ToList();
                fullClear.Should().BeOfType <List <byte> >();
                fullClear.Should().NotBeNullOrEmpty();

                var isValid = value.TryClear(skip: 6, take: 2, settings: settings);
                value.Should().BeEquivalentTo(partialClear);
                isValid.Should().BeTrue();

                value   = Encoding.UTF8.GetBytes("0123456789").ToList();
                isValid = value.TryClear(skip: 0, take: 10, settings: settings);
                value.Should().BeEquivalentTo(fullClear);
                isValid.Should().BeTrue();

                value   = Encoding.UTF8.GetBytes("0123456789").ToList();
                isValid = value.TryClear(skip: 6, take: 2, clearAfterUse: true, settings: settings);
                value.Should().BeEquivalentTo(fullClear);
                isValid.Should().BeTrue();

                if (boundsMode != BoundsMode.Ninja && boundsMode != BoundsMode.List)
                {
                    continue;
                }

                value   = Encoding.UTF8.GetBytes("0123456789").ToList();
                isValid = value.TryClear(skip: 10, take: 10, settings: settings);
                value.Should().NotBeEquivalentTo(fullClear);
                isValid.Should().BeTrue();

                isValid = value.TryClear(skip: 7, take: 10, clearAfterUse: true, settings: settings);
                value.Should().BeEquivalentTo(fullClear);
                isValid.Should().BeTrue();
            }
        }