Beispiel #1
0
        public void TestSetNextLine()
        {
            using (var app = new VisualStudioApp()) {
                var project = OpenDebuggerProjectAndBreak(app, "SetNextLine.py", 7);

                var doc = app.Dte.Documents.Item("SetNextLine.py");
                ((TextSelection)doc.Selection).GotoLine(8);
                ((TextSelection)doc.Selection).EndOfLine(false);
                //((TextSelection)doc.Selection).CharRight(false, 5);
                //((TextSelection)doc.Selection).CharRight(true, 1);
                var curLine = ((TextSelection)doc.Selection).CurrentLine;

                app.Dte.Debugger.SetNextStatement();
                app.Dte.Debugger.StepOver(true);
                WaitForMode(app, dbgDebugMode.dbgBreakMode);

                var curFrame = app.Dte.Debugger.CurrentStackFrame;
                var local    = curFrame.Locals.Item("y");
                Assert.AreEqual("100", local.Value);

                try {
                    curFrame.Locals.Item("x");
                    Assert.Fail("Expected exception, x should not be defined");
                } catch {
                }

                app.Dte.Debugger.TerminateAll();

                WaitForMode(app, dbgDebugMode.dbgDesignMode);
            }
        }
Beispiel #2
0
        public void TestProps_MethodAccess_WrongParams()
        {
            var derived = new DerivedClass();

            try
            {
                int value = derived.InvokeMethod <int>("MathMethod", 12, "aaa", true);
                Assert.Fail("Error expected. ");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Found 3 [MathMethod] method(s) on [DotNetLittleHelpers.Tests.DerivedClass], however none matches the provided arguments: [Int32,String,Boolean]", ex.Message);
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
            }

            try
            {
                derived.InvokeMethod("AVoidMethod", 12, "aaa", true);
                Assert.Fail("Error expected. ");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Found 1 [AVoidMethod] method(s) on [DotNetLittleHelpers.Tests.DerivedClass], however none matches the provided arguments: [Int32,String,Boolean]", ex.Message);
                Assert.IsInstanceOfType(ex, typeof(ArgumentException));
            }
        }
Beispiel #3
0
        public void TestDeleteEmployees()
        {
            onSetUp();
            var employeeBuilder = new EmployeeBuilder().setName(NAME);

            employeeRepository.AddEmployees(new List <Employee>()
            {
                employeeBuilder.CreateEmployee()
            });

            var removeEmployeeRequest = new RemoveEmployeeRequest()
            {
                Name = NAME
            };

            employeeController.Delete(removeEmployeeRequest);

            try
            {
                employeeController.Get(NAME);
                Assert.Fail("Expected exception to be thrown.");
            }
            catch (NoSuchEntityException e)
            {
                Assert.IsTrue(e.Message.Contains(NAME));
            }
        }
        public void Test_Sync_TooManyErrors()
        {
            var thrower = new ErrorThrower(4, () => throw new InvalidOperationException("Boo"));

            try
            {
                Retrier.Retry(() => thrower.Work(), TimeSpan.FromMilliseconds(10));
                Assert.Fail("Error expected");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(ex.GetType(), typeof(AggregateException));
                Assert.AreEqual(3, ((AggregateException)ex).InnerExceptions.Count);
                Assert.IsTrue(((AggregateException)ex).InnerExceptions.All(x => x.Message == "Boo"));
            }

            try
            {
                thrower = new ErrorThrower(4, () => throw new InvalidOperationException("Boo"));
                Assert.AreEqual(0, thrower.AttemptNumber);

                Retrier.Retry(() => thrower.WorkVoid(), TimeSpan.FromMilliseconds(10));
                Assert.Fail("Error expected");
            }
            catch (Exception ex)
            {
                Assert.AreEqual(ex.GetType(), typeof(AggregateException));
                Assert.AreEqual(3, ((AggregateException)ex).InnerExceptions.Count);
                Assert.IsTrue(((AggregateException)ex).InnerExceptions.All(x => x.Message == "Boo"));
            }
        }
Beispiel #5
0
        public void SoftAssertAssertFailed()
        {
            var tester = GetBaseTest();

            tester.Setup();
            tester.Log = new FileLogger(string.Empty, $"{Guid.NewGuid()}.txt");
            tester.SoftAssert.Assert(() => throw new Exception("broke"), "Name1");
            tester.SoftAssert.Assert(() => throw new Exception("broke again"), "Name2");
            try
            {
                tester.SoftAssert.FailTestIfAssertFailed();
                MicroAssert.Fail();
                NUnit.Framework.Assert.Fail();
            }
            catch (AggregateException aggregateException)
            {
                MicroAssert.AreEqual(
                    2,
                    aggregateException.InnerExceptions.Count,
                    "Incorrect number of inner exceptions in Soft Assert");
                NUnit.Framework.Assert.AreEqual(
                    2,
                    aggregateException.InnerExceptions.Count,
                    "Incorrect number of inner exceptions in Soft Assert");
            }
        }
Beispiel #6
0
        public void TestProcessManifestRejectsDuplicateGtins()
        {
            onSetUp();
            var quantity        = 12;
            var inboundManifest = new InboundManifestRequestModel()
            {
                WarehouseId = WAREHOUSE_ID,
                Gcp         = GCP,
                OrderLines  = new List <OrderLine>()
                {
                    new OrderLine()
                    {
                        gtin     = GTIN,
                        quantity = quantity
                    },
                    new OrderLine()
                    {
                        gtin     = GTIN,
                        quantity = quantity
                    }
                }
            };

            try
            {
                inboundOrderController.Post(inboundManifest);
                Assert.Fail("Expected exception to be thrown.");
            }
            catch (ValidationException e)
            {
                Assert.IsTrue(e.Message.Contains(GTIN));
            }
        }
Beispiel #7
0
        public ITestProperty SetValue(string textEntry)
        {
            AssertIsVisible();
            AssertIsModifiable();
            ResetLastMessage();

            INakedObjectAdapter nakedObjectAdapter = owningObject.NakedObject;

            try {
                field.GetNakedObject(nakedObjectAdapter);

                var parseableFacet = field.ReturnSpec.GetFacet <IParseableFacet>();

                INakedObjectAdapter newValue = parseableFacet.ParseTextEntry(textEntry, manager);

                IConsent consent = ((IOneToOneAssociationSpec)field).IsAssociationValid(nakedObjectAdapter, newValue);
                LastMessage = consent.Reason;

                Assert.IsFalse(consent.IsVetoed, string.Format("Content: '{0}' is not valid. Reason: {1}", textEntry, consent.Reason));

                ((IOneToOneAssociationSpec)field).SetAssociation(nakedObjectAdapter, textEntry.Trim().Equals("") ? null : newValue);
            }
            catch (InvalidEntryException) {
                Assert.Fail("Entry not recognised " + textEntry);
            }
            return(this);
        }
        [TestMethod]//Pending #9227
        public void SetUserOnTestIsPassedThroughToAuthorizer()
        {
            SetUser("svenFoo", "Bar");
            try {
                GetTestService(typeof(SimpleRepository <Foo>)).GetAction("New Instance").AssertIsVisible();
                Assert.Fail("Should not get to here");
            } catch (Exception e) {
                Assert.AreEqual("User name: svenFoo, IsInRole Bar = True", e.Message);
            }

            SetUser("svenBar", "Bar");
            try {
                GetTestService(typeof(SimpleRepository <Foo>)).GetAction("New Instance").AssertIsVisible();
                Assert.Fail("Should not get to here");
            } catch (Exception e) {
                Assert.AreEqual("User name: svenBar, IsInRole Bar = True", e.Message);
            }

            SetUser("svenFoo");
            try {
                GetTestService(typeof(SimpleRepository <Foo>)).GetAction("New Instance").AssertIsVisible();
                Assert.Fail("Should not get to here");
            } catch (Exception e) {
                Assert.AreEqual("User name: svenFoo, IsInRole Bar = False", e.Message);
            }
        }
Beispiel #9
0
        public async Task DpsPollyRetryExecuteAsyncTest(Type actualEx, HttpStatusCode?code)
        {
            // Delay時間の指定は、テスト時間を縮めるため
            DpsPolly target    = CreateTestTarget(1, 2);
            var      startAt   = DateTime.UtcNow;
            int      execCount = 0;

            try
            {
                await target.ExecuteAsync(() =>
                {
                    execCount++;
                    throw CreateException(actualEx, code);
                });
            }
            catch (Exception)
            {
                // リトライ1回なので、2回実行
                Assert.AreEqual(2, execCount);

                // 2秒(1 * 2)以上経過しているはず。
                var elapsedTime = DateTime.UtcNow - startAt;
                // 本来なら期待結果を2にしたいが、微妙な揺らぎで1.999xになることがあるため、1.9とする。
                Assert.AreEqual(-1, TimeSpan.FromSeconds(1.9).CompareTo(elapsedTime), $"経過時間:{elapsedTime}");
                return;
            }
            Assert.Fail();
        }
Beispiel #10
0
        public async Task DpsPollyExecuteAsyncDefaultTest()
        {
            // アプリケーション設定がない場合デフォルト設定(3回、3秒)で動作する
            DpsPolly target    = CreateTestTarget();
            var      startAt   = DateTime.UtcNow;
            int      execCount = 0;

            try
            {
                // 引数を付けているのはUnauthorizedExceptionは引数つきコンストラクタしかないため。
                await target.ExecuteAsync(() =>
                {
                    execCount++;
                    throw CreateDpsException(HttpStatusCode.Forbidden);
                });
            }
            catch (Exception)
            {
                // 初回 + リトライ回数を期待する
                Assert.AreEqual(4, execCount);
                // 18秒(0 + 3 + 6 + 9)以上経過しているはず。
                var elapsedTime = DateTime.UtcNow - startAt;
                Assert.AreEqual(-1, TimeSpan.FromSeconds(18).CompareTo(elapsedTime), $"経過時間:{elapsedTime}");
                return;
            }
            Assert.Fail();
        }
Beispiel #11
0
        public void IotHubPollyRetryExecuteTest(Type actualEx)
        {
            // Delay時間の指定は、テスト時間を縮めるため
            IotHubPolly target    = CreateTestTarget(1, 2);
            var         startAt   = DateTime.UtcNow;
            int         execCount = 0;

            try
            {
                // 引数を付けているのはIotHubExceptionは引数つきコンストラクタしかないため。
                target.Execute(() =>
                {
                    execCount++;
                    throw Activator.CreateInstance(actualEx, "message") as Exception;
                });
            }
            catch (Exception)
            {
                // リトライ1回なので、2回実行
                Assert.AreEqual(2, execCount);

                // 2秒(1 * 2)以上経過しているはず。
                var elapsedTime = DateTime.UtcNow - startAt;
                Assert.AreEqual(-1, new TimeSpan(0, 0, 2).CompareTo(elapsedTime), $"経過時間:{elapsedTime}");
                return;
            }
            Assert.Fail();
        }
Beispiel #12
0
        public async Task IotHubPollyExecuteAsyncDefaultTest()
        {
            // アプリケーション設定がない場合デフォルト設定(3回、3秒)で動作する
            IotHubPolly target    = CreateTestTarget();
            var         startAt   = DateTime.UtcNow;
            int         execCount = 0;

            try
            {
                // 引数を付けているのはUnauthorizedExceptionは引数つきコンストラクタしかないため。
                await target.ExecuteAsync(() =>
                {
                    execCount++;
                    throw new IotHubException("message");
                });
            }
            catch (Exception)
            {
                // 初回 + リトライ回数を期待する
                Assert.AreEqual(4, execCount);
                // 18秒(0 + 3 + 6 + 9)以上経過しているはず。
                var elapsedTime = DateTime.UtcNow - startAt;
                Assert.AreEqual(-1, new TimeSpan(0, 0, 18).CompareTo(elapsedTime), $"経過時間:{elapsedTime}");
                return;
            }
            Assert.Fail();
        }
        public void Test04After30MinutesCanNotAddABookInTheCart()
        {
            IYourBooksApplication application = objectProvider.YourBooksApplication();

            application.RegisterClient("marcos", "123");
            Client aClient   = application.Login("marcos", "123");
            Guid   aCartId   = application.CreateCart(aClient.Id, aClient.Password);
            string aBook     = objectProvider.ABook();
            string otherBook = objectProvider.OtherBook();


            application.AddAQuantityOfAnItem(1, aBook, aCartId);
            application.Clock.UpdateSomeMinutes(30); // minutes

            try
            {
                application.AddAQuantityOfAnItem(1, otherBook, aCartId);
                Assert.Fail();
            }
            catch (TimeoutException e)
            {
                Assert.AreEqual("The cart has been expired", e.Message);

                Cart aCart = application.GetCart(aCartId);
                Assert.IsFalse(aCart.HasABook(otherBook));
            }
        }
        public void TransferenciaEntreCuentasConFondosInsuficientesArrojaUnError()
        {
            // Preparación
            Exception expectedException = null;
            Cuenta    origen            = new Cuenta()
            {
                Fondos = 0
            };
            Cuenta destino = new Cuenta()
            {
                Fondos = 0
            };
            decimal montoATransferir = 5m;
            var     servicio         = new ServicioDeTransferenciasSinMocks();

            // Prueba
            try
            {
                servicio.TransferirEntreCuentas(origen, destino, montoATransferir);
                Assert.Fail("Un error debió ser arrojado");
            }
            catch (Exception ex)
            {
                expectedException = ex;
            }

            // Verificación
            Assert.IsTrue(expectedException is ApplicationException);
            Assert.AreEqual("La cuenta origen no tiene fondos suficientes para realizar la operación", expectedException.Message);
        }
Beispiel #15
0
 public ITestProperty GetPropertyById(string id)
 {
     ITestProperty[] q = Properties.Where(x => x.Id == id).ToArray();
     if (q.Count() != 1)
     {
         Assert.Fail("No Property with Id '" + id + "'");
     }
     return(q.Single());
 }
Beispiel #16
0
 public void TestParseInvalidString()
 {
     try {
         value.ParseTextEntry("yes");
         Assert.Fail("Invalid string");
     }
     catch (Exception e) {
         Assert.IsInstanceOfType(e, typeof(InvalidEntryException));
     }
 }
Beispiel #17
0
 public override void TestParseEmptyString()
 {
     try {
         object newValue = value.ParseTextEntry("");
         Assert.IsNull(newValue);
     }
     catch (Exception) {
         Assert.Fail();
     }
 }
Beispiel #18
0
 public ITestProperty AssertSetObjectInvalid(ITestObject testObject)
 {
     try {
         AssertSetObjectIsValid(testObject);
     }
     catch (AssertFailedException) {
         // expected
         return(this);
     }
     Assert.Fail("Object {0} was allowed in field {1} : expected it to be invalid", testObject, field);
     return(this);
 }
Beispiel #19
0
        public void EditabilityUsingSpecificTypeAuthorizer()
        {
            ITestObject qux = GetTestService(typeof(SimpleRepository <Qux>)).GetAction("New Instance").InvokeReturnObject();

            try {
                qux.GetPropertyByName("Prop1").AssertIsModifiable();
                Assert.Fail("Should not get to here");
            }
            catch (Exception e) {
                Assert.AreEqual("QuxAuthorizer#IsEditable, user: sven, target: qux1, memberName: Prop1", e.Message);
            }
        }
Beispiel #20
0
 public ITestObject AssertCannotBeSaved()
 {
     try {
         AssertCanBeSaved();
     }
     catch (AssertFailedException) {
         // expected
         return(this);
     }
     Assert.Fail("Object should not be saveable");
     return(this); // for compiler
 }
Beispiel #21
0
        public void VisibilityUsingSpecificTypeAuthorizer()
        {
            ITestObject foo = GetTestService(typeof(SimpleRepository <Foo>)).GetAction("New Instance").InvokeReturnObject();

            try {
                foo.GetPropertyByName("Prop1").AssertIsVisible();
                Assert.Fail("Should not get to here");
            }
            catch (Exception e) {
                Assert.AreEqual("FooAuthorizer#IsVisible, user: sven, target: foo1, memberName: Prop1", e.Message);
            }
        }
Beispiel #22
0
 public void TestDiscontinueNonexistentProduct()
 {
     onSetUp();
     try
     {
         productController.Discontinue(GTIN);
         Assert.Fail("Expected exception to be thrown.");
     }
     catch (NoSuchEntityException e)
     {
         Assert.IsTrue(e.Message.Contains(GTIN));
     }
 }
        public static void AssertSpecsContain(Type type, ITypeSpecBuilder[] specs)
        {
            foreach (var spec in specs)
            {
                if (type.FullName == spec.FullName)
                {
                    AssertSpec(type, spec);
                    return;
                }
            }

            Assert.Fail("Spec missing: " + type.FullName);
        }
Beispiel #24
0
 public ITestProperty GetPropertyByName(string name)
 {
     ITestProperty[] q = Properties.Where(x => x.Name == name).ToArray();
     if (!q.Any())
     {
         Assert.Fail("No Property named '" + name + "'");
     }
     if (q.Count() > 1)
     {
         Assert.Fail("More than one Property named '" + name + "'");
     }
     return(q.Single());
 }
Beispiel #25
0
 public void TestGetNonExistentCompany()
 {
     onSetUp();
     try
     {
         companyController.Get(GCP);
         Assert.Fail("Expected exception to be thrown.");
     }
     catch (NoSuchEntityException e)
     {
         Assert.IsTrue(e.Message.Contains(GCP));
     }
 }
Beispiel #26
0
 public void TestGetEmployeeInNonexistentWarehouse()
 {
     onSetUp();
     try
     {
         var employees = employeeController.Get(WAREHOUSE_ID).Employees.ToList();
         Assert.Fail("Expected exception to be thrown.");
     }
     catch (NoSuchEntityException e)
     {
         Assert.IsTrue(e.Message.Contains(WAREHOUSE_ID.ToString()));
     }
 }
Beispiel #27
0
 public void TestGetNonExistentEmployee()
 {
     onSetUp();
     try
     {
         employeeController.Get(NAME);
         Assert.Fail("Expected exception to be thrown.");
     }
     catch (NoSuchEntityException e)
     {
         Assert.IsTrue(e.Message.Contains(NAME));
     }
 }
Beispiel #28
0
        public void TestProps_GetValue_WrongType()
        {
            var baseClass = new BaseClass();

            try
            {
                string str = baseClass.GetPropertyValue <string>("PrivateIntProp");
                Assert.Fail("Error expected. Wrong cast, duh");
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Unable to cast object of type 'System.Int32' to type 'System.String'.", ex.Message);
            }
        }
Beispiel #29
0
        public void TestDiscontinueNonexistantProduct()
        {
            onSetUp();
            var nonExistantGtin = "12345678";

            try
            {
                productController.Discontinue(nonExistantGtin);
                Assert.Fail("Expected exception to be thrown.");
            }
            catch (NoSuchEntityException e)
            {
                Assert.IsTrue(e.Message.Contains(nonExistantGtin));
            }
        }
        public void Test000CanNotRegisterADuplicatedUser()
        {
            IYourBooksApplication application = objectProvider.YourBooksApplication();

            application.RegisterClient("marcos", "123");
            try
            {
                application.RegisterClient("marcos", "123");
                Assert.Fail();
            }
            catch (RegisterException e)
            {
                Assert.AreEqual("User already registered", e.Message);
            }
        }