Ejemplo n.º 1
0
        public void Test_plugins_are_searched_in_plugins_directory()
        {
            using (var tmpDir = new TemporaryDirectory())
            {
                var tagPath = Path.Combine(tmpDir.Path, "AasxAcmePluginForSomething.plugin");
                File.WriteAllText(tagPath, @"ACME tag!");

                var pluginPath = Path.Combine(tmpDir.Path, "AasxAcmePluginForSomething.dll");
                File.WriteAllText(pluginPath, @"ACME!");

                var pluginDllInfos = Plugins.TrySearchPlugins(tmpDir.Path);

                Assert.AreEqual(1, pluginDllInfos.Count);

                Assert.AreEqual(null, pluginDllInfos[0].Args);
                Assert.AreEqual(null, pluginDllInfos[0].Options);
                Assert.AreEqual(null, pluginDllInfos[0].DefaultOptions);
                Assert.AreEqual(pluginPath, pluginDllInfos[0].Path);
            }
        }
Ejemplo n.º 2
0
        public void Test_that_command_line_arguments_after_the_additional_config_file_overrule()
        {
            using (var tmpDir = new TemporaryDirectory())
            {
                var jsonOptionsPath = Path.Combine(tmpDir.Path, "options-test.json");

                const string text = @"{ ""PluginDir"": ""/somewhere/from/the/additional"" }";
                File.WriteAllText(jsonOptionsPath, text);

                string exePath            = Common.AasxPackageExplorerExe();
                var    optionsInformation = App.InferOptions(
                    exePath, new[]
                {
                    "-read-json", jsonOptionsPath,
                    "-plugin-dir", "/somewhere/from/the/command/line",
                });

                Assert.AreEqual("/somewhere/from/the/command/line", optionsInformation.PluginDir);
            }
        }
Ejemplo n.º 3
0
        public void IssueBybeanels01a()
        {
            //sample = [np.array([[1., 2., 3.]]),np.array([[4., 5., 6.]]),np.array([[7., 8., 9.]])]
            //for test in sample:
            //    n = np.argmax(test[0])
            //    print(n)
            //# expected:
            //# 2
            //# 2
            //# 2
            var result = new List <int>();
            var nc     = np.array(new[] { np.array(new[] { 1, 2, 3 }), np.array(new[] { 4, 5, 6 }), np.array(new[] { 7, 8, 9 }) });

            for (int i = 0; i < nc.len; i++)
            {
                var n = np.argmax(nc[i]).asscalar <int>();
                result.Add(n);
            }
            Assert.AreEqual("2, 2, 2", string.Join(", ", result));
        }
Ejemplo n.º 4
0
        public void IssueByBanyc2()
        {
            var a = np.array(new[, ] {
                { 1, 2, 3 }, { 4, 5, 6 }
            });
            var    b        = np.array(new[] { 1, 2 });
            string tempFile = Path.GetTempFileName() + ".npz";

            Console.WriteLine(tempFile);
            np.savez(tempFile, new [] { a, b });
            var data = np.load(tempFile, allow_pickle: true);
            var a1   = new NDarray(data.self["arr_0"]);

            Console.WriteLine(a1.repr);
            var b1 = new NDarray(data.self["arr_1"]);

            Console.WriteLine(b1.repr);
            Assert.AreEqual("array([[1, 2, 3],\n       [4, 5, 6]])", a1.repr);
            Assert.AreEqual(@"array([1, 2])", b1.repr);
        }
Ejemplo n.º 5
0
        public void QuestionBySimonBuehler()
        {
            //import numpy as np
            //bboxes = np.empty([999, 4])
            //keep_idx = np.array([2, 6, 7, 8, 9, 13])
            //bboxes = bboxes[keep_idx]
            //>>> bboxes.shape
            //(6, 4)
            var bboxes   = np.empty(new Shape(999, 4));
            var keep_idx = np.array(new[] { 2, 6, 7, 8, 9, 13 });

            bboxes = bboxes[keep_idx];
            Assert.AreEqual("(6, 4)", bboxes.shape.ToString());

            //>>> np.where(keep_idx > 4)[0]
            //array([1, 2, 3, 4, 5], dtype = int64)
            var x = np.where (keep_idx > 4)[0];

            Assert.AreEqual("array([1, 2, 3, 4, 5], dtype=int64)", x.repr);
        }
Ejemplo n.º 6
0
        public void RequireGrad()
        {
            //>>> x = torch.tensor([[1., -1.], [1., 1.]], requires_grad=True)
            //>>> out = x.pow(2).sum()
            //>>> out.backward()
            //>>> x.grad
            //tensor([[ 2.0000, -2.0000],
            //        [ 2.0000,  2.0000]])
#if TODO
            var x = torch.tensor(new[, ] {
                { 1.0, -1.0 }, { 1.0, 1.0 }
            }, requires_grad: true);
            var @out = x.pow(2).sum();
            @out.backward();
            var given    = x.grad;
            var expected = "tensor([[ 2.0000, -2.0000],\n" +
                           "        [ 2.0000,  2.0000]])";
            Assert.AreEqual(expected, given.repr);
#endif
        }
Ejemplo n.º 7
0
        public void MailTo_Coverage()
        {
            Document doc = new Document();
            bool     isMailAddress;

            // localpart
            doc.Text = "mailto:";
            Assert.AreEqual(-1, UriMarker.Inst.GetUriEnd(doc, 0, out isMailAddress));

            doc.Text = "mailto:a";
            Assert.AreEqual(-1, UriMarker.Inst.GetUriEnd(doc, 0, out isMailAddress));

            doc.Text = "mailto:'";
            Assert.AreEqual(-1, UriMarker.Inst.GetUriEnd(doc, 0, out isMailAddress));

            doc.Text = "mailto:ab";
            Assert.AreEqual(-1, UriMarker.Inst.GetUriEnd(doc, 0, out isMailAddress));

            doc.Text = "mailto:a'";
            Assert.AreEqual(-1, UriMarker.Inst.GetUriEnd(doc, 0, out isMailAddress));

            // domain (first char)
            doc.Text = "mailto:a@";
            Assert.AreEqual(-1, UriMarker.Inst.GetUriEnd(doc, 0, out isMailAddress));

            doc.Text = "mailto:a@'";
            Assert.AreEqual(-1, UriMarker.Inst.GetUriEnd(doc, 0, out isMailAddress));

            doc.Text = "mailto:a@a";
            Assert.AreEqual(10, UriMarker.Inst.GetUriEnd(doc, 0, out isMailAddress));

            // domain (remainings)
            doc.Text = "mailto:a@a";
            Assert.AreEqual(10, UriMarker.Inst.GetUriEnd(doc, 0, out isMailAddress));

            doc.Text = "mailto:a@a'";
            Assert.AreEqual(10, UriMarker.Inst.GetUriEnd(doc, 0, out isMailAddress));

            doc.Text = "mailto:a@aa";
            Assert.AreEqual(11, UriMarker.Inst.GetUriEnd(doc, 0, out isMailAddress));
        }
Ejemplo n.º 8
0
        public void LineHeadIndexFromCharIndex()
        {
            TextBuffer       text;
            SplitArray <int> lhi;

            MakeTestData(out text, out lhi);

            int i = 0;

            for ( ; i < 32; i++)
            {
                Assert.AreEqual(0, TextUtil.GetLineHeadIndexFromCharIndex(text, lhi, i));
            }
            for ( ; i < 33; i++)
            {
                Assert.AreEqual(32, TextUtil.GetLineHeadIndexFromCharIndex(text, lhi, i));
            }
            for ( ; i < 37; i++)
            {
                Assert.AreEqual(33, TextUtil.GetLineHeadIndexFromCharIndex(text, lhi, i));
            }
            for ( ; i < 38; i++)
            {
                Assert.AreEqual(37, TextUtil.GetLineHeadIndexFromCharIndex(text, lhi, i));
            }
            for ( ; i < 52; i++)
            {
                Assert.AreEqual(38, TextUtil.GetLineHeadIndexFromCharIndex(text, lhi, i));
            }
            for ( ; i < 53; i++)
            {
                Assert.AreEqual(52, TextUtil.GetLineHeadIndexFromCharIndex(text, lhi, i));
            }
            for ( ; i <= 71; i++)
            {
                Assert.AreEqual(53, TextUtil.GetLineHeadIndexFromCharIndex(text, lhi, i));
            }
            MyAssert.Throws <AssertException>(delegate {
                TextUtil.GetLineHeadIndexFromCharIndex(text, lhi, i);
            });
        }
Ejemplo n.º 9
0
        public void pvTest()
        {
            // What is the present value (e.g., the initial investment)
            // of an investment that needs to total $15692.93
            // after 10 years of saving $100 every month?  Assume the
            // interest rate is 5% (annually) compounded monthly.

            // >>> np.pv(0.05/12, 10*12, -100, 15692.93)
            // -100.00067131625819
            //

            #if TODO
            var given    = np.pv(0.05 / 12, 10 * 12, -100, 15692.93);
            var expected =
                "-100.00067131625819";
            Assert.AreEqual(expected, given.repr);
            #endif
            // By convention, the negative sign represents cash flow out
            // (i.e., money not available today).  Thus, to end up with
            // $15,692.93 in 10 years saving $100 a month at 5% annual
            // interest, one’s initial deposit should also be $100.

            // If any input is array_like, pv returns an array of equal shape.
            // Let’s compare different interest rates in the example above:

            // >>> a = np.array((0.05, 0.04, 0.03))/12
            // >>> np.pv(a, 10*12, -100, 15692.93)
            // array([ -100.00067132,  -649.26771385, -1273.78633713])
            //

            #if TODO
            given    = a = np.array((0.05, 0.04, 0.03)) / 12;
            given    = np.pv(a, 10 * 12, -100, 15692.93);
            expected =
                "array([ -100.00067132,  -649.26771385, -1273.78633713])";
            Assert.AreEqual(expected, given.repr);
            #endif
            // So, to end up with the same $15692.93 under the same $100 per month
            // “savings plan,” for annual interest rates of 4% and 3%, one would
            // need initial investments of $649.27 and $1273.79, respectively.
        }
        public void Previously_Instantiated_Objects_Will_Be_Returned_Until_The_Cache_Is_Cleared()
        {
            // Arrange
            var dictionary = new Dictionary <string, object>
            {
                { "CustomerId", 1 },
                { "FirstName", "Bob" },
                { "LastName", "Smith" }
            };

            // Act
            var customer = Slapper.AutoMapper.Map <Customer>(dictionary);

            // Assert
            Assert.AreEqual("Bob", customer.FirstName);

            // Arrange
            var dictionary2 = new Dictionary <string, object> {
                { "CustomerId", 1 }
            };

            // Act
            var customer2 = Slapper.AutoMapper.Map <Customer>(dictionary2);

            // Assert that this will be "Bob" because the identifier of the Customer object was the same,
            // so we recieved back the cached instance of the Customer object.
            Assert.AreEqual("Bob", customer2.FirstName);

            // Arrange
            var dictionary3 = new Dictionary <string, object> {
                { "CustomerId", 1 }
            };

            Slapper.AutoMapper.Cache.ClearInstanceCache();

            // Act
            var customer3 = Slapper.AutoMapper.Map <Customer>(dictionary3);

            // Assert
            Assert.Null(customer3.FirstName);
        }
Ejemplo n.º 11
0
        public void testToJsonLeafTypesViaFields()
        {
            AllPrimitiveLeafTypes template = new AllPrimitiveLeafTypes();

            String [] expressions    = AllPrimitiveLeafTypes.testFieldExpressions;
            Object[]  expectedValues = AllPrimitiveLeafTypes.testExpectedFieldValues(template);

            AllPrimitiveLeafTypes result;
            Json2Object           j2O = new Json2Object();
            //j2O.setToUseFields();
            Type        type = typeof(AllPrimitiveLeafTypes);
            Object2Json o2J  = new Object2Json();

            o2J.NodeExpander = new FieldReflectionNodeExpander();
            //todo json 2 object should understand TypeAliaser
            o2J.TypeAliaser       = (t) => { return(t.FullName); };
            o2J.TypeAliasProperty = j2O.TypeSpecifier;
            string json = o2J.toJson(template);

            System.Console.Out.WriteLine("testToJsonLeafTypesViaFields json:" + json);
            result = (AllPrimitiveLeafTypes)j2O.toObject(json);

            for (int done = 0; done < expressions.Length; done++)
            {
                string expression = expressions[done];
                object value      = type.GetField(expression).GetValue(result);
                if (value != null)
                {
                    Type underlyingType = value.GetType();
                    if (Nullable.GetUnderlyingType(underlyingType) != null)
                    {
                        underlyingType = Nullable.GetUnderlyingType(underlyingType);
                    }
                    if (underlyingType == typeof(Char) || underlyingType == typeof(char))
                    {
                        value = value.ToString();
                    }
                }
                Assert.AreEqual(expectedValues[done], value, expression + " value");
            }
        }
        public void ReadProperty_String_QuotedPrintable()
        {
            const string encodedValue =
                "LABEL;" +
                "HOME;" +
                "ENCODING=QUOTED-PRINTABLE:" +
                "129 15th Street #3=0D=0A" +
                "Minneapolis, MN 55403=0D=0A" +
                "United States of America";

            const string decodedValue =
                "129 15th Street #3\r\n" +
                "Minneapolis, MN 55403\r\n" +
                "United States of America";

            vCardStandardReader reader =
                new vCardStandardReader();

            // Read the property string.  It should
            // be decoded by the reader.

            vCardProperty property =
                reader.ReadProperty(encodedValue);

            Assert.AreEqual(
                "LABEL",
                property.Name,
                "The name of the property should be LABEL.");

            Assert.IsTrue(
                property.Subproperties.Contains("HOME"),
                "The property should have a subproperty called HOME.");

            // Now for the big test.  The loaded property
            // value should be decoded.  It should not have the
            // quoted-printable escape sequences.

            Assert.AreEqual(
                decodedValue,
                property.ToString());
        }
Ejemplo n.º 13
0
        public void Constructor_Name()
        {
            vCardProperty property = new vCardProperty("NAME");

            Assert.AreEqual(
                "NAME",
                property.Name,
                "The name is incorrect.");

            Assert.IsNull(
                property.Value,
                "The value should be null.");

            Assert.IsNotNull(
                property.Subproperties,
                "The subproperties collection was not created.");

            Assert.IsEmpty(
                property.Subproperties,
                "The subproperties collection should be empty.");
        }
Ejemplo n.º 14
0
        public void spectral_normTest()
        {
            // >>> m = spectral_norm(nn.Linear(20, 40))
            // >>> m
            // Linear(in_features=20, out_features=40, bias=True)
            // >>> m.weight_u.size()
            // torch.Size([40])
            //

            #if TODO
            var given = m = spectral_norm(nn.Linear(20, 40));
            given = m;
            var expected =
                "Linear(in_features=20, out_features=40, bias=True)";
            Assert.AreEqual(expected, given.repr);
            given    = m.weight_u.size();
            expected =
                "torch.Size([40])";
            Assert.AreEqual(expected, given.repr);
            #endif
        }
        public void TestCalcTriangle()
        {
            //right triangle
            Triangle2D t1            = new Triangle2D(3, 4, 5);
            double     area          = t1.GetArea();
            bool       isRectangular = t1.IsRectangular;

            Assert.AreEqual(6, area);
            Assert.AreEqual(true, isRectangular);

            //non-rectangular triangle
            Triangle2D t2 = new Triangle2D(5, 5, 8);

            area          = t2.GetArea();
            isRectangular = t2.IsRectangular;
            Assert.AreEqual(12, area);
            Assert.AreEqual(false, isRectangular);

            //incorrect input
            Microsoft.VisualStudio.TestTools.UnitTesting.Assert.ThrowsException <Exception>(() => new Triangle2D(5, 10, 5));
        }
Ejemplo n.º 16
0
        public void ndarray_comparison_operators()
        {
            var a = np.array(1, 2, 3);

            // comparison with a scalar
            Assert.AreEqual(new[] { true, false, false }, (a < 2).GetData());
            Assert.AreEqual(new[] { true, true, false }, (a <= 2).GetData());
            Assert.AreEqual(new[] { false, false, true }, (a > 2).GetData());
            Assert.AreEqual(new[] { false, true, true }, (a >= 2).GetData());
            Assert.AreEqual(new[] { false, true, false }, (a.equals(2)).GetData());
            Assert.AreEqual(new[] { true, false, true }, (a.not_equals(2)).GetData());
            // comparison with an array
            var b = (np.ones(new Shape(3), np.int32) * 2);

            Assert.AreEqual(new[] { true, false, false }, (a < b).GetData());
            Assert.AreEqual(new[] { true, true, false }, (a <= b).GetData());
            Assert.AreEqual(new[] { false, false, true }, (a > b).GetData());
            Assert.AreEqual(new[] { false, true, true }, (a >= b).GetData());
            Assert.AreEqual(new[] { false, true, false }, (a.equals(b)).GetData());
            Assert.AreEqual(new[] { true, false, true }, (a.not_equals(b)).GetData());
        }
Ejemplo n.º 17
0
        protected void AssertBinaryFileContent(string actualFile, string expectedFile)
        {
            var actual   = File.ReadAllBytes(actualFile);
            var expected = File.ReadAllBytes(expectedFile);

            Assert.AreEqual(expected.Length, actual.Length);
            for (int i = 0; i < actual.Length; i++)
            {
                if (actual[i] != expected[i])
                {
                    StringBuilder sb1 = new StringBuilder();
                    StringBuilder sb2 = new StringBuilder();
                    for (int j = 0; j < 8 && i + j < expected.Length; j++)
                    {
                        sb1.AppendFormat("{0:X2} ", expected[i + j]);
                        sb2.AppendFormat("{0:X2} ", actual[i + j]);
                    }
                    Assert.Fail("Files differ at index {0}: expected <{1}> but found <{2}>", i, sb1, sb2);
                }
            }
        }
Ejemplo n.º 18
0
        public void ReadWriteProperty_RevisionDate()
        {
            vCard card = new vCard();

            card.RevisionDate = DateTime.Parse("01/01/2001 01:01 AM");

            Assert.AreEqual(
                DateTime.Parse("01/01/2001 01:01 AM"),
                card.RevisionDate,
                "The RevisionDate property is not working.");

            // format not working right when it comes to write out the REV property
            // REV:2013-09-18T15:39:21Z
            // REV:20130918T153921Z

            DateTime date = DateTime.Parse("11/25/2012 01:01 AM");

            string revDate = date.ToString("s") + "Z";

            Assert.AreEqual("2012-11-25T01:01:00Z", revDate);
        }
Ejemplo n.º 19
0
        public void ndarray_indexing_setter2()
        {
            // using string indices
            var x = np.arange(10);

            Assert.AreEqual("2", x[2].str);
            x["2"] = (NDarray)22;
            Assert.AreEqual("22", x[2].str);
            Assert.AreEqual("8", x[-2].str);
            x["-2"] = (NDarray)88;
            Assert.AreEqual("88", x[-2].str);
            var y = x.reshape(new Shape(2, 5));

            Assert.AreEqual("88", y[1, 3].str);
            y["1, 3"] = (NDarray)888;
            Assert.AreEqual("888", y[1, 3].str);
            Assert.AreEqual("array([ 0,  1, 22,  3,  4])", y[0].repr);
            Assert.AreEqual("22", y[0][2].str);
            y["0"]["2"] = (NDarray)222;
            Assert.AreEqual("222", y[0][2].str);
        }
Ejemplo n.º 20
0
        public void Add()
        {
            IOrderByClause clause = new OrderByClause("field1 desc, field2");
            var            item   = new OrderByItem("field3", SortOrder.Descending);

            clause.Add(item);

            Assert.AreEqual("field1 desc,field2,field3 desc", clause.ToString());

            // can't add existing field
            Assert.Throws <ArgumentException>(() =>
            {
                clause.Add("field2");
            });

            clause.AddAlways("field1", SortOrder.Ascending);
            Assert.AreEqual("field2,field3 desc,field1", clause.ToString());

            item.Reverse();
            Assert.AreEqual("field2,field3,field1", clause.ToString());
        }
Ejemplo n.º 21
0
        public void QuestionByPiyushspss()
        {
            // np.column_stack(np.where(mat > 0))

            //>>> a = np.array([1, 0, 0, 1, 2, 3, 0, 1]).reshape(2, 4)
            //         >>> a
            //array([[1, 0, 0, 1],
            //       [2, 3, 0, 1]])
            //>>> np.column_stack(a)
            //array([[1, 2],
            //       [0, 3],
            //       [0, 0],
            //       [1, 1]])
            //>>> np.where(a > 0)
            //(array([0, 0, 1, 1, 1], dtype = int64), array([0, 3, 0, 1, 3], dtype = int64))
            //>>> np.column_stack(np.where(a > 0))
            //array([[0, 0],
            //       [0, 3],
            //       [1, 0],
            //       [1, 1],
            //       [1, 3]], dtype = int64)
            //>>>
            var a        = np.array(new[] { 1, 0, 0, 1, 2, 3, 0, 1 }).reshape(2, 4);
            var expected =
                "array([[1, 2],\n" +
                "       [0, 3],\n" +
                "       [0, 0],\n" +
                "       [1, 1]])";

            Assert.AreEqual(expected, np.column_stack(a).repr);
            // note: this was a bug, now you don't get a python tuple back, but an array of NDarrays instead so the following line just doesn't compile any more
            //Assert.AreEqual("(array([0, 0, 1, 1, 1], dtype=int64), array([0, 3, 0, 1, 3], dtype=int64))", np.where(a > 0).repr);
            expected =
                "array([[0, 0],\n" +
                "       [0, 3],\n" +
                "       [1, 0],\n" +
                "       [1, 1],\n" +
                "       [1, 3]], dtype=int64)";
            Assert.AreEqual(expected, np.column_stack(np.where (a > 0)).repr);
        }
Ejemplo n.º 22
0
        public void GetLineIndexFromCharIndex()
        {
            SplitArray <int> lhi = new SplitArray <int>(32, 32);

            lhi.Add(0);
            lhi.Add(32);
            lhi.Add(33);
            lhi.Add(37);
            lhi.Add(38);
            lhi.Add(52);
            lhi.Add(53);

            int i = 0;

            for ( ; i < 32; i++)
            {
                Assert.AreEqual(0, TextUtil.GetLineIndexFromCharIndex(lhi, i));
            }
            for ( ; i < 33; i++)
            {
                Assert.AreEqual(1, TextUtil.GetLineIndexFromCharIndex(lhi, i));
            }
            for ( ; i < 37; i++)
            {
                Assert.AreEqual(2, TextUtil.GetLineIndexFromCharIndex(lhi, i));
            }
            for ( ; i < 38; i++)
            {
                Assert.AreEqual(3, TextUtil.GetLineIndexFromCharIndex(lhi, i));
            }
            for ( ; i < 52; i++)
            {
                Assert.AreEqual(4, TextUtil.GetLineIndexFromCharIndex(lhi, i));
            }
            for ( ; i < 53; i++)
            {
                Assert.AreEqual(5, TextUtil.GetLineIndexFromCharIndex(lhi, i));
            }
            Assert.AreEqual(6, TextUtil.GetLineIndexFromCharIndex(lhi, 54));
        }
Ejemplo n.º 23
0
        public void UnitOfWorkCommitTest()
        {
            var data = new List <Employee>
            {
                new Employee()
                {
                    EmployeeId = 1, FirstName = "Cawi", BirthDate = new DateTime(1989, 10, 30)
                },
            }.AsQueryable();

            var dbSetEmployeesMock = new Mock <IDbSet <Employee> >();

            dbSetEmployeesMock.Setup(m => m.Provider).Returns(data.Provider);
            dbSetEmployeesMock.Setup(m => m.Expression).Returns(data.Expression);
            dbSetEmployeesMock.Setup(m => m.ElementType).Returns(data.ElementType);
            dbSetEmployeesMock.Setup(m => m.GetEnumerator()).Returns(data.GetEnumerator());

            var context = new Mock <PayrollContext>();

            context.Setup(x => x.Employees).Returns(dbSetEmployeesMock.Object);

            var databaseFactory = new DatabaseFactory(context.Object);
            var unitOfWork      = new UnitOfWork(databaseFactory);

            var employeeDepartmentRepository = new EmployeeDepartmentRepository(databaseFactory);
            var employeeRepository           = new EmployeeRepository(databaseFactory, employeeDepartmentRepository);

            employeeRepository.Add(new Employee()
            {
                BirthDate = DateTime.Now, FirstName = "New"
            });
            unitOfWork.Commit();

            dbSetEmployeesMock.Verify(x => x.Add(It.IsAny <Employee>()));
            context.Verify(x => x.SaveChanges());

            var count = employeeRepository.GetAll().Count();

            Assert.AreEqual(count, 2);
        }
        public void SaveNewObjectCallsPersistingPersistedRecursively()
        {
            Assert.AreEqual(0, Persistor.Instances <Order>().Count());

            var order = CreateNewTransientOrder();

            order.Name = Guid.NewGuid().ToString();
            var adapter = Save(order);

            Assert.AreEqual(1, order.GetEvents()["Persisting"], "persisting");
            Assert.AreEqual(5, Persistor.Instances <Order>().Count());

            Assert.IsTrue(Persistor.Instances <Order>().All(i => i.PersistingCalled));

            // handle quirk in EF which swaps out object on save
            // fix this when EF updated
            var orderAfter = (Order)adapter.Object;

            Assert.AreEqual(1, orderAfter.GetEvents()["Persisted"], "persisted");
            Assert.AreEqual(1, orderAfter.GetEvents()["Updating"], "updating");
            Assert.AreEqual(1, orderAfter.GetEvents()["Updated"], "updated");
        }
        public void Constructor_String_EmailType()
        {
            // Create a non-Internet email address.  Note:
            // currently address formats are not validated.
            // This means any type can be designated in the
            // constructor.  However, this test may fail if
            // validation is implemented in the future.

            vCardEmailAddress email = new vCardEmailAddress(
                TestEmailAddress,
                vCardEmailAddressType.eWorld);

            Assert.AreEqual(
                TestEmailAddress,
                email.Address,
                "The EmailAddress is not correct.");

            Assert.AreEqual(
                vCardEmailAddressType.eWorld,
                email.EmailType,
                "The EmailType is not correct.");
        }
Ejemplo n.º 26
0
        public void UpdateEmployeeUsingOnlyIdTest()
        {
            //Arrange
            var databaseFactory    = new DatabaseFactory();
            var employeeRepository = new Repository <Employee>(databaseFactory);
            var unitOfWork         = new UnitOfWork(databaseFactory);

            //Act
            var employee = new Employee()
            {
                EmployeeId = 1
            };

            employeeRepository.Update(employee);
            employee.LastName = "Updated";
            unitOfWork.Commit();

            var updatedEmployee = employeeRepository.GetById(1);

            //Asset
            Assert.AreEqual(updatedEmployee.LastName, "Updated");
        }
Ejemplo n.º 27
0
        public void stripTest()
        {
            // >>> c = np.array(['aAaAaA', '  aA  ', 'abBABba'])
            // >>> c
            // array(['aAaAaA', '  aA  ', 'abBABba'],
            //     dtype='|S7')
            // >>> np.char.strip(c)
            // array(['aAaAaA', 'aA', 'abBABba'],
            //     dtype='|S7')
            // >>> np.char.strip(c, 'a') # 'a' unstripped from c[1] because whitespace leads
            // array(['AaAaA', '  aA  ', 'bBABb'],
            //     dtype='|S7')
            // >>> np.char.strip(c, 'A') # 'A' unstripped from c[1] because (unprinted) ws trails
            // array(['aAaAa', '  aA  ', 'abBABba'],
            //     dtype='|S7')
            //

            #if TODO
            var given = c = np.array({ 'aAaAaA', '  aA  ', 'abBABba' });
            given = c;
            var expected =
                "array(['aAaAaA', '  aA  ', 'abBABba'],\n" +
                "    dtype='|S7')";
            Assert.AreEqual(expected, given.repr);
            given    = np.char.strip(c);
            expected =
                "array(['aAaAaA', 'aA', 'abBABba'],\n" +
                "    dtype='|S7')";
            Assert.AreEqual(expected, given.repr);
            given = np.char.strip(c, 'a') # 'a' unstripped from c {
                1
            } because whitespace leads;
            expected =
                "array(['AaAaA', '  aA  ', 'bBABb'],\n" +
                "    dtype='|S7')";
            Assert.AreEqual(expected, given.repr);
            given = np.char.strip(c, 'A') # 'A' unstripped from c {
                1
            } because(unprinted) ws trails;
Ejemplo n.º 28
0
        public void VerifyThatFailsIfMatcherDoesNotMatchValue()
        {
            object  expected = new NamedObject("expected");
            object  actual   = new NamedObject("actual");
            Matcher matcher  = Is.EqualTo(expected);

            try
            {
                Verify.That(actual, matcher);
            }
            catch (ExpectationException e)
            {
                Assert.AreEqual(
                    Environment.NewLine +
                    "Expected: " + matcher + Environment.NewLine +
                    "Actual:   <" + actual + ">(NMockTests.NamedObject)",
                    e.Message);
                return;
            }

            Assert.Fail("Verify.That should have failed");
        }
Ejemplo n.º 29
0
        public void CanPrependCustomMessageToDescriptionOfFailure()
        {
            object  expected = new NamedObject("expected");
            object  actual   = new NamedObject("actual");
            Matcher matcher  = Is.EqualTo(expected);

            try
            {
                Verify.That(actual, matcher, "message {0} {1}", "0", 1);
            }
            catch (ExpectationException e)
            {
                Assert.AreEqual(
                    "message 0 1" + Environment.NewLine +
                    "Expected: " + matcher + Environment.NewLine +
                    "Actual:   <" + actual + ">(NMockTests.NamedObject)",
                    e.Message);
                return;
            }

            Assert.Fail("Verify.That should have failed");
        }
Ejemplo n.º 30
0
        public void QuestionByPiyushspss()
        {
            // np.column_stack(np.where(mat > 0))

            //>>> a = np.array([1, 0, 0, 1, 2, 3, 0, 1]).reshape(2, 4)
            //         >>> a
            //array([[1, 0, 0, 1],
            //       [2, 3, 0, 1]])
            //>>> np.column_stack(a)
            //array([[1, 2],
            //       [0, 3],
            //       [0, 0],
            //       [1, 1]])
            //>>> np.where(a > 0)
            //(array([0, 0, 1, 1, 1], dtype = int64), array([0, 3, 0, 1, 3], dtype = int64))
            //>>> np.column_stack(np.where(a > 0))
            //array([[0, 0],
            //       [0, 3],
            //       [1, 0],
            //       [1, 1],
            //       [1, 3]], dtype = int64)
            //>>>
            var a        = np.array(new[] { 1, 0, 0, 1, 2, 3, 0, 1 }).reshape(2, 4);
            var expected =
                "array([[1, 2],\n" +
                "       [0, 3],\n" +
                "       [0, 0],\n" +
                "       [1, 1]])";

            Assert.AreEqual(expected, np.column_stack(a).repr);
            Assert.AreEqual("(array([0, 0, 1, 1, 1], dtype=int64), array([0, 3, 0, 1, 3], dtype=int64))", np.where (a > 0).repr);
            expected =
                "array([[0, 0],\n" +
                "       [0, 3],\n" +
                "       [1, 0],\n" +
                "       [1, 1],\n" +
                "       [1, 3]], dtype=int64)";
            Assert.AreEqual(expected, np.column_stack(np.where (a > 0)).repr);
        }