public void TestIndexOfWithNullItemContained()
        {
            int[]             integers       = new int[] { 12, 34, 67, 89, 42 };
            StringTransformer testCollection = new StringTransformer(integers);

            Assert.AreEqual(4, testCollection.IndexOf(null));
        }
        public void StringTransformer()
        {
            Func <Key, Key> transformOperation = s => s.ToString().Replace("is", "isnt");
            var             st = new StringTransformer(transformOperation);

            Assert.AreEqual(transformOperation(_transformString), st.Transform(_transformString));
        }
        public void TestIsFixedSizeViaIList()
        {
            int[]             integers       = new int[] { 12, 34, 67, 89 };
            StringTransformer testCollection = new StringTransformer(integers);

            Assert.IsTrue((testCollection as IList).IsFixedSize);
        }
Ejemplo n.º 4
0
        internal static int TransformStringValue(Win32Api.RegValueType type,
                                                 IntPtr pSrcData, int cbSrcData,
                                                 Data dst, StringTransformer transformer, StringFormat dstFormat)
        {
            string value = "";

            if (pSrcData != IntPtr.Zero)
            {
                value = PtrToString(pSrcData, cbSrcData / Data.BytesPerChar(dstFormat));
            }

            bool removedNullChar = false;

            if ((type == Win32Api.RegValueType.REG_SZ ||
                 type == Win32Api.RegValueType.REG_EXPAND_SZ) &&
                value.EndsWith("\0"))
            {
                value           = value.Remove(value.Length - 1);
                removedNullChar = true;
            }

            value = transformer(value);

            if (removedNullChar)
            {
                value += "\0";
            }

            return(dst.FillWithString(new ManagedString(value), dstFormat,
                                      Data.NullCharHandling.NotAddingIfNotPresent));
        }
Ejemplo n.º 5
0
        public StringTransformerTests()
        {
            _transformer = new StringTransformer();

            _testingString = "test";
            _testingBytes  = Encoding.UTF8.GetBytes(_testingString);
        }
        public void TestThrowOnAddViaGenericICollection()
        {
            StringTransformer testCollection = new StringTransformer(new int[0]);

            Assert.Throws <NotSupportedException>(
                delegate() { (testCollection as ICollection <string>).Add("12345"); }
                );
        }
Ejemplo n.º 7
0
        public void StringIntoByte()
        {
            var t = new StringTransformer();

            t.TransformPost("test")
            .Should()
            .BeEquivalentTo(Encoding.UTF8.GetBytes("test"));
        }
        public void TestContainsViaIList()
        {
            int[]             integers       = new int[] { 1234, 6789 };
            StringTransformer testCollection = new StringTransformer(integers);

            Assert.IsTrue((testCollection as IList).Contains("1234"));
            Assert.IsFalse((testCollection as IList).Contains("4321"));
        }
        public void TestThrowOnInsertViaIList()
        {
            StringTransformer testCollection = new StringTransformer(new int[0]);

            Assert.Throws <NotSupportedException>(
                delegate() { (testCollection as IList).Insert(0, "12345"); }
                );
        }
        public void TestThrowOnRemoveAtViaIList()
        {
            StringTransformer testCollection = new StringTransformer(new int[1]);

            Assert.Throws <NotSupportedException>(
                delegate() { (testCollection as IList).RemoveAt(0); }
                );
        }
        public void TestThrowOnReplaceByIndexerViaIList()
        {
            StringTransformer testCollection = new StringTransformer(new int[1]);

            Assert.Throws <NotSupportedException>(
                delegate() { (testCollection as IList)[0] = "12345"; }
                );
        }
        public void TestCopyConstructor()
        {
            int[]             integers       = new int[] { 12, 34, 56, 78 };
            StringTransformer testCollection = new StringTransformer(integers);

            string[] strings = new string[] { "12", "34", "56", "78" };
            CollectionAssert.AreEqual(strings, testCollection);
        }
        public void TestThrowOnClearViaGenericICollection()
        {
            StringTransformer testCollection = new StringTransformer(new int[1]);

            Assert.Throws <NotSupportedException>(
                delegate() { (testCollection as ICollection <string>).Clear(); }
                );
        }
Ejemplo n.º 14
0
        private static IDatabase <string, string> ApplyStringTransformation
        (
            [NotNull] this IDatabase <byte[], byte[]> database
        )
        {
            var transformer = new StringTransformer();

            return(database.WithTransform(transformer, transformer));
        }
        public void TestThrowOnRemoveViaGenericICollection()
        {
            int[]             integers       = new int[] { 12, 34, 67, 89 };
            StringTransformer testCollection = new StringTransformer(integers);

            Assert.Throws <NotSupportedException>(
                delegate() { (testCollection as ICollection <string>).Remove("89"); }
                );
        }
        public void TestThrowOnRemoveViaIList()
        {
            int[]             integers       = new int[] { 1234, 6789 };
            StringTransformer testCollection = new StringTransformer(integers);

            Assert.Throws <NotSupportedException>(
                delegate() { (testCollection as IList).Remove("6789"); }
                );
        }
Ejemplo n.º 17
0
        public void ByteIntoString()
        {
            var t = new StringTransformer();

            var bytes = Encoding.UTF8.GetBytes("test");

            t.TransformPre(bytes)
            .Should()
            .BeEquivalentTo("test");
        }
        public void TestRetrieveByIndexerViaIList()
        {
            int[]             integers       = new int[] { 12, 34, 67, 89 };
            StringTransformer testCollection = new StringTransformer(integers);

            Assert.AreEqual("12", (testCollection as IList)[0]);
            Assert.AreEqual("34", (testCollection as IList)[1]);
            Assert.AreEqual("67", (testCollection as IList)[2]);
            Assert.AreEqual("89", (testCollection as IList)[3]);
        }
        public void TestIndexOfViaIList()
        {
            int[]             integers       = new int[] { 12, 34, 67, 89 };
            StringTransformer testCollection = new StringTransformer(integers);

            Assert.AreEqual(0, (testCollection as IList).IndexOf("12"));
            Assert.AreEqual(1, (testCollection as IList).IndexOf("34"));
            Assert.AreEqual(2, (testCollection as IList).IndexOf("67"));
            Assert.AreEqual(3, (testCollection as IList).IndexOf("89"));
        }
        public void TestThrowOnCopyToTooSmallArray()
        {
            int[]             inputIntegers  = new int[] { 12, 34, 56, 78 };
            StringTransformer testCollection = new StringTransformer(inputIntegers);

            string[] outputStrings = new string[testCollection.Count - 1];
            Assert.Throws <ArgumentException>(
                delegate() { testCollection.CopyTo(outputStrings, 0); }
                );
        }
        public void TestCopyToArray()
        {
            int[]             inputIntegers  = new int[] { 12, 34, 56, 78 };
            StringTransformer testCollection = new StringTransformer(inputIntegers);

            string[] inputStrings  = new string[] { "12", "34", "56", "78" };
            string[] outputStrings = new string[testCollection.Count];
            testCollection.CopyTo(outputStrings, 0);

            CollectionAssert.AreEqual(inputStrings, outputStrings);
        }
        public void TestSynchronization()
        {
            StringTransformer testCollection = new StringTransformer(new int[0]);

            if (!(testCollection as ICollection).IsSynchronized)
            {
                lock ((testCollection as ICollection).SyncRoot) {
                    Assert.AreEqual(0, testCollection.Count);
                }
            }
        }
        private void GridMooving_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
        {
            try
            {
                TextBox tb = e.EditingElement as TextBox;

                TextHandler.DotReplace(tb);

                float temp = float.Parse(tb.Text);

                int index = gridMooving.SelectedIndex;

                switch (e.Column.SortMemberPath)
                {
                case "GoodsQuantity":
                {
                    MoovingGoodsToSale gridRow = gridMooving.SelectedItem as MoovingGoodsToSale;

                    string goodsName     = gridRow.GoodsName;
                    string warehouseName = gridRow.WarehouseSourse;

                    string command = "SELECT [GoodsInWarehouses].[GoodsBalance] FROM [GoodsInWarehouses] " +
                                     "INNER JOIN [Warehouses] " +
                                     "ON [GoodsInWarehouses].[WarehouseName] = [Warehouses].[WarehouseID] " +
                                     "INNER JOIN [Goods] " +
                                     "ON [GoodsInWarehouses].[GoodsName] = [Goods].[GoodsID] " +
                                     "WHERE [Goods].[GoodsName] = '" + goodsName + "' " +
                                     "AND [Warehouses].[WarehouseName] = '" + warehouseName + "'";

                    float goodsQuantity = float.Parse(new DataBaseReader(this.sqlConnect).GetString(command));

                    moovingList[index].GoodsQuantity =
                        goodsQuantity >= temp?temp.ToString() : goodsQuantity.ToString();
                }
                break;

                case "GoodsPrice":
                    moovingList[index].GoodsPrice = StringTransformer.TransformDecimal(temp.ToString());
                    break;
                }
            }

            catch
            {
                ErrorMessages.UncorrectData();
            }

            finally
            {
                UpdateGridMooving(ListAction.EditList);
            }
        }
        public void TestSynchronizationOfIListWithoutICollection()
        {
            MockFactory         mockery        = new MockFactory();
            Mock <IList <int> > mockedIList    = mockery.CreateMock <IList <int> >();
            StringTransformer   testCollection = new StringTransformer(mockedIList.MockObject);

            if (!(testCollection as ICollection).IsSynchronized)
            {
                lock ((testCollection as ICollection).SyncRoot) {
                    mockedIList.Expects.One.GetProperty(p => p.Count).WillReturn(12345);
                    int count = testCollection.Count;
                    Assert.AreEqual(12345, count); // ;-)
                }
            }
        }
        public void TestSynchronizationOfIListWithoutICollection()
        {
            Mockery           mockery        = new Mockery();
            IList <int>       mockedIList    = mockery.NewMock <IList <int> >();
            StringTransformer testCollection = new StringTransformer(mockedIList);

            if (!(testCollection as ICollection).IsSynchronized)
            {
                lock ((testCollection as ICollection).SyncRoot) {
                    Expect.Once.On(mockedIList).GetProperty("Count").Will(Return.Value(12345));
                    int count = testCollection.Count;
                    Assert.AreEqual(12345, count); // ;-)
                }
            }
        }
        public IActionResult Excercise6(string value)
        {
            var stringTransformer = new StringTransformer();

            try
            {
                ViewBag.Result = stringTransformer.Reverse(value);
            }
            catch (Exception e)
            {
                ViewBag.Error = e.Message;
            }

            return(View());
        }
        public void TestTypesafeEnumerator()
        {
            int[]             inputIntegers  = new int[] { 12, 34, 56, 78 };
            StringTransformer testCollection = new StringTransformer(inputIntegers);

            List <string> outputStrings = new List <string>();

            foreach (string value in testCollection)
            {
                outputStrings.Add(value);
            }

            string[] inputStrings = new string[] { "12", "34", "56", "78" };
            CollectionAssert.AreEqual(inputStrings, outputStrings);
        }
        public void TestEnumeratorReset()
        {
            int[]             integers       = new int[] { 1234, 6789 };
            StringTransformer testCollection = new StringTransformer(integers);

            IEnumerator <string> stringEnumerator = testCollection.GetEnumerator();

            Assert.IsTrue(stringEnumerator.MoveNext());
            Assert.IsTrue(stringEnumerator.MoveNext());
            Assert.IsFalse(stringEnumerator.MoveNext());

            stringEnumerator.Reset();

            Assert.IsTrue(stringEnumerator.MoveNext());
            Assert.IsTrue(stringEnumerator.MoveNext());
            Assert.IsFalse(stringEnumerator.MoveNext());
        }
Ejemplo n.º 29
0
        public void WorksIGuess()
        {
            var st = new StringTransformer();

            // using (var fs = File.Open("copy.db", FileMode.OpenOrCreate))
            using (var ms = new MemoryStream())
            {
                using (var lowlevelDBIODevice = new StringDB5_0_0LowlevelDatabaseIODevice(ms, true))
                    using (var dbIODevice = new DatabaseIODevice(lowlevelDBIODevice))
                        using (var iodb = new IODatabase(dbIODevice))
                            using (var db = new TransformDatabase <byte[], byte[], string, string>(iodb, st, st))
                            {
                                db.Insert("test", "value");
                                db.InsertRange(new KeyValuePair <string, string>[]
                                {
                                    new KeyValuePair <string, string>("a,", "c,"),
                                    new KeyValuePair <string, string>("b,", "d,"),
                                });

                                File.WriteAllBytes("sdb.db", ms.ToArray());

                                db.EnumerateAggressively(2)
                                .Should()
                                .BeEquivalentTo
                                (
                                    new KeyValuePair <string, string>[]
                                {
                                    new KeyValuePair <string, string>("test", "value"),
                                    new KeyValuePair <string, string>("a,", "c,"),
                                    new KeyValuePair <string, string>("b,", "d,"),
                                }
                                );
                            }

                ms.Seek(0, SeekOrigin.Begin);
                // ms.CopyTo(fs);
            }
        }
        public void TestIsReadOnly()
        {
            StringTransformer testCollection = new StringTransformer(new int[0]);

            Assert.IsTrue(testCollection.IsReadOnly);
        }