public async Task EchoGrain_Timeout_Result() { grain = GrainClient.GrainFactory.GetGrain <IEchoTaskGrain>(Guid.NewGuid()); TimeSpan delay30 = TimeSpan.FromSeconds(30); TimeSpan delay60 = TimeSpan.FromSeconds(60); Stopwatch sw = new Stopwatch(); sw.Start(); try { int res = await grain.BlockingCallTimeoutAsync(delay60); Assert.Fail("BlockingCallTimeout should not have completed successfully, but returned " + res); } catch (Exception exc) { while (exc is AggregateException) { exc = exc.InnerException; } Assert.IsInstanceOfType(exc, typeof(TimeoutException), "Received exception type: {0}", exc); } sw.Stop(); Assert.IsTrue(TimeIsLonger(sw.Elapsed, delay30), "Elapsted time out of range: {0}", sw.Elapsed); Assert.IsTrue(TimeIsShorter(sw.Elapsed, delay60), "Elapsted time out of range: {0}", sw.Elapsed); }
public async Task Get_ShouldReturnNotFoundIfPropertyDoesNotExists() { var result = await _propertiesControllerMock.Get(9); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, typeof(NotFoundResult)); }
public async Task GetAll_ShouldReturnListOfPropertyEntitiesType() { var result = await _propertyRepositoryMock.GetAll(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, _propertyListMock.GetType()); }
public void TestMoveIntoRightWallPlayerOne() { // Given var game = Match.GetInstance(); game.StartNewGame(true); var map = game.Map; var ship = game.GetPlayer(1).Ship; const ShipCommand direction = ShipCommand.MoveRight; // When while (ship.X + ship.Width < map.Width - 1) { ship.Command = direction; game.Update(); } ship.Command = direction; game.Update(); // Then Assert.IsInstanceOfType(map.GetEntity(map.Width - 1, ship.Y), typeof(Wall), "Rightmost tile is not a wall after ship moved into it"); Assert.IsInstanceOfType(map.GetEntity(ship.X, ship.Y), typeof(Ship), "Leftmost ship tile is missing after moving into a right wall"); Assert.IsInstanceOfType(map.GetEntity(ship.X + 1, ship.Y), typeof(Ship), "Center ship tile is missing after moving into a right wall"); Assert.IsInstanceOfType(map.GetEntity(ship.X + 2, ship.Y), typeof(Ship), "Rightmost ship tile is missing after moving into a right wall"); Assert.AreEqual(map.Width - 4, ship.X, "Ship x is not " + (map.Width - 4) + "as expected after moving into a right wall"); }
public async Task Constructor_Bad_Await() { try { int id = random.Next(); IBadConstructorTestGrain grain = GrainClient.GrainFactory.GetGrain <IBadConstructorTestGrain>(id); await grain.DoSomething(); Assert.Fail("Expected ThrowSomething call to fail as unable to Activate grain"); } catch (TimeoutException te) { Console.WriteLine("Received timeout: " + te); throw; // Fail test } catch (Exception exc) { Console.WriteLine("Received exception: " + exc); Exception e = exc.GetBaseException(); Console.WriteLine("Nested exception type: " + e.GetType().FullName); Console.WriteLine("Nested exception message: " + e.Message); Assert.IsInstanceOfType(e, typeof(Exception), "Did not get expected exception type returned: " + e); Assert.IsNotInstanceOfType(e, typeof(InvalidOperationException), "Did not get expected exception type returned: " + e); Assert.IsTrue(e.Message.Contains("Constructor"), "Did not get expected exception message returned: " + e.Message); } }
public async Task GetAll_ShouldReturnListOfBrokerEntitiesType() { var result = await _brokerRepositoryMock.GetAll(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, _brokerListMock.GetType()); }
public void TestShipCanDestroyOwnShields() { // Given var game = Match.GetInstance(); game.StartNewGame(true); var map = game.Map; var player = game.GetPlayer(1); var ship = player.Ship; ship.Command = ShipCommand.BuildShield; game.Update(); // When ship.Command = ShipCommand.Shoot; game.Update(); // Then Assert.IsInstanceOfType(map.GetEntity(ship.X, ship.Y - 1), typeof(Shield), "Left shield tile is missing"); Assert.IsNull(map.GetEntity(ship.X + 1, ship.Y - 1), "Center shield tile was not destroyed"); Assert.IsInstanceOfType(map.GetEntity(ship.X + 2, ship.Y - 1), typeof(Shield), "Right shield tile is missing"); }
public async Task GetAll_ShouldReturnListOfPropertyListItemDTOType() { var result = await _propertyServiceMock.GetAll(); Assert.IsNotNull(result); Assert.IsInstanceOfType(result, _propertyListItemDtoMock.GetType()); }
public void CastGrainRefUpCastFromGrandchild() { // GeneratorTestDerivedGrain1Reference derives from GeneratorTestGrainReference // GeneratorTestDerivedGrain2Reference derives from GeneratorTestGrainReference // GeneratorTestDerivedDerivedGrainReference derives from GeneratorTestDerivedGrain2Reference GrainReference cast; GrainReference grain = (GrainReference)GrainClient.GrainFactory.GetGrain <IGeneratorTestDerivedDerivedGrain>(GetRandomGrainId()); // Parent cast = (GrainReference)grain.AsReference <IGeneratorTestDerivedGrain2>(); Assert.IsInstanceOfType(cast, typeof(IGeneratorTestDerivedDerivedGrain)); Assert.IsInstanceOfType(cast, typeof(IGeneratorTestDerivedGrain2)); Assert.IsInstanceOfType(cast, typeof(IGeneratorTestGrain)); // Cross-cast outside the inheritance hierarchy should not work Assert.IsNotInstanceOfType(cast, typeof(IGeneratorTestDerivedGrain1)); // Grandparent cast = (GrainReference)grain.AsReference <IGeneratorTestGrain>(); Assert.IsInstanceOfType(cast, typeof(IGeneratorTestDerivedDerivedGrain)); Assert.IsInstanceOfType(cast, typeof(IGeneratorTestGrain)); // Cross-cast outside the inheritance hierarchy should not work Assert.IsNotInstanceOfType(cast, typeof(IGeneratorTestDerivedGrain1)); }
public void AddItemToBasket_GivenUnavailableStock_ReturnsBadRequest() { // Arrange var userId = 1; this.basketService.GetByUserId(userId).Returns(new Basket()); var basketItem = new BasketItem(); this.mapperService.Map(Arg.Any <Item>()).Returns(basketItem); const int itemId = 1; const int quantity = 2; this.itemService.Get(itemId).Returns(new Item { Stock = 1 }); // Act var actionResult = controller.AddBasketEntry(userId, new BasketEntry { ItemId = itemId, Quantity = quantity }); // Assert Assert.IsInstanceOfType(actionResult, typeof(BadRequestErrorMessageResult)); }
public void Checkout_ReturnsInvoiceOk() { // Arrange var userId = 1; this.userService.Get("TestUser").Returns(new User { Id = userId }); var basket = new Basket(); basket.Add(new BasketItem { ItemId = 2 }); this.basketService.GetByUserId(userId).Returns(basket); this.itemService.Get(2).Returns(new Item { Id = 2, Stock = 4 }); // Act var actionResult = controller.Checkout("TestUser"); // Assert Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <Invoice>)); }
public void MustPopulateObject() { var obj1 = new TestContrato() { Id = 1, Contrato_Id = "string", DateCreated = DateTime.Today.AddDays(-10), NumeroContrato = "string", NumeroProposta = "string", TitularId = 2 }; var obj2 = new TestContrato2() { Id = 2, NumeroContrato = "Alterado", NumeroContrato2 = "Alterado2", TitularId = null }; var result = obj1.PopulateProperties(obj2); Assert.IsInstanceOfType(result, typeof(TestContrato)); var resultType = (TestContrato)result; resultType.Id.ShouldBe(obj2.Id); resultType.NumeroContrato.ShouldBe(obj2.NumeroContrato); obj2.NumeroProposta.ShouldBeNull(); resultType.NumeroProposta.ShouldBeEqual(obj2.NumeroProposta); resultType.DateCreated.ShouldBe(obj1.DateCreated); }
public void EchoGrain_Timeout_Wait() { grain = GrainClient.GrainFactory.GetGrain <IEchoTaskGrain>(Guid.NewGuid()); TimeSpan delay30 = TimeSpan.FromSeconds(30); // grain call timeout (set in config) TimeSpan delay45 = TimeSpan.FromSeconds(45); TimeSpan delay60 = TimeSpan.FromSeconds(60); Stopwatch sw = new Stopwatch(); sw.Start(); Task <int> promise = grain.BlockingCallTimeoutAsync(delay60); bool ok = promise.ContinueWith(t => { if (!t.IsFaulted) { Assert.Fail("BlockingCallTimeout should not have completed successfully"); } Exception exc = t.Exception; while (exc is AggregateException) { exc = exc.InnerException; } Assert.IsInstanceOfType(exc, typeof(TimeoutException), "Received exception type: {0}", exc); }).Wait(delay45); sw.Stop(); Assert.IsTrue(ok, "Wait should not have timed-out. The grain call should have time out."); Assert.IsTrue(TimeIsLonger(sw.Elapsed, delay30), "Elapsted time out of range: {0}", sw.Elapsed); Assert.IsTrue(TimeIsShorter(sw.Elapsed, delay60), "Elapsted time out of range: {0}", sw.Elapsed); }
public async Task GetAll_ShouldReturnListOfPropertyEntityType() { var result = await _propertiesControllerMock.Get() as OkNegotiatedContentResult <List <PropertyListItemDTO> >; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); Assert.IsInstanceOfType(result.Content, _propertyListItemDTOMock.GetType()); }
public async Task GetAll_ShouldReturnListOfBrokerDTOEntityType() { var result = await _brokerControllerMock.Get() as OkNegotiatedContentResult <List <BrokerDTO> >; Assert.IsNotNull(result); Assert.IsNotNull(result.Content); Assert.IsInstanceOfType(result.Content, _brokerDTOListMock.GetType()); }
public void CastGrainRefCastFromMyType() { GrainReference grain = (GrainReference)GrainClient.GrainFactory.GetGrain <ISimpleGrain>(random.Next(), SimpleGrain.SimpleGrainNamePrefix); GrainReference cast = (GrainReference)grain.AsReference <ISimpleGrain>(); Assert.IsInstanceOfType(cast, grain.GetType()); Assert.IsInstanceOfType(cast, typeof(ISimpleGrain)); }
public void CastGrainRefUpCastFromChild() { // GeneratorTestDerivedGrain1Reference extends GeneratorTestGrainReference GrainReference grain = (GrainReference)GrainClient.GrainFactory.GetGrain <IGeneratorTestDerivedGrain1>(GetRandomGrainId()); GrainReference cast = (GrainReference)grain.AsReference <IGeneratorTestGrain>(); Assert.IsInstanceOfType(cast, typeof(IGeneratorTestDerivedGrain1)); Assert.IsInstanceOfType(cast, typeof(IGeneratorTestGrain)); }
public void Serialization_ValueTypePhase2() { ValueTypeTestData data = new ValueTypeTestData(4); object copy = SerializationManager.RoundTripSerializationForTesting(data); Assert.IsInstanceOfType(copy, typeof(ValueTypeTestData), "Deserialized result is of wrong type"); Assert.AreEqual <int>(4, ((ValueTypeTestData)copy).GetValue(), "Deserialized result is incorrect"); }
public void Serialization_ValueTypePhase1() { ValueTypeTestData data = new ValueTypeTestData(4); object obj = SerializationManager.DeepCopy(data); Assert.IsInstanceOfType(obj, typeof(ValueTypeTestData), "Deserialized result is of wrong type"); Assert.AreEqual <int>(4, ((ValueTypeTestData)obj).GetValue(), "Deserialized result is incorrect"); }
public async Task PubSub_Store_WriteError() { SetErrorInjection(PubSubStoreProviderName, ErrorInjectionPoint.BeforeWrite); var exception = await Xunit.Assert.ThrowsAsync <OrleansException>(() => Test_PubSub_Stream(StreamProviderName, StreamId)); Assert.IsInstanceOfType(exception.InnerException, typeof(StorageProviderInjectedError)); }
public void GetBasket_GivenAnUnknownUserName_ReturnsBasketOk() { // Arrange this.userService.Get("TestUser").Returns(new User()); // Act var actionResult = controller.GetBasket("Unknown User"); // Assert Assert.IsInstanceOfType(actionResult, typeof(BadRequestErrorMessageResult)); }
public void GetBasket_ReturnsBasketOk() { // Arrange this.userService.Get("TestUser").Returns(new User()); // Act var actionResult = controller.GetBasket("TestUser"); // Assert Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <Basket>)); }
public void Get_Returns_Ok() { // Arrange // Act var actionResult = controller.Get(); // Assert Assert.IsInstanceOfType(actionResult, typeof(OkNegotiatedContentResult <IEnumerable <Item> >)); }
public void ChangePasswordSuccess_ReturnsView() { // Arrange AccountController controller = GetAccountController(); // Act ActionResult result = controller.ChangePasswordSuccess(); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void LogOn_Get_ReturnsView() { // Arrange AccountController controller = GetAccountController(); // Act ActionResult result = controller.LogOn(); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); }
public void Register_Get_ReturnsView() { // Arrange AccountController controller = GetAccountController(); // Act ActionResult result = controller.Register(); // Assert Assert.IsInstanceOfType(result, typeof(ViewResult)); Assert.AreEqual(10, ((ViewResult)result).ViewData["PasswordLength"]); }
public void CastInternalCastFromMyType() { var serviceName = typeof(SimpleGrain).FullName; GrainReference grain = (GrainReference)GrainClient.GrainFactory.GetGrain <ISimpleGrain>(random.Next(), SimpleGrain.SimpleGrainNamePrefix); IAddressable cast = GrainReference.CastInternal( typeof(ISimpleGrain), (GrainReference gr) => { throw new InvalidOperationException("Should not need to create a new GrainReference wrapper"); }, grain, Utils.CalculateIdHash(serviceName)); Assert.IsInstanceOfType(cast, typeof(ISimpleGrain)); }
public void CastInternalCastUpFromChild() { // GeneratorTestDerivedGrain1Reference extends GeneratorTestGrainReference GrainReference grain = (GrainReference)GrainClient.GrainFactory.GetGrain <IGeneratorTestDerivedGrain1>(GetRandomGrainId()); var serviceName = typeof(GeneratorTestGrain).FullName; IAddressable cast = GrainReference.CastInternal( typeof(IGeneratorTestGrain), (GrainReference gr) => { throw new InvalidOperationException("Should not need to create a new GrainReference wrapper"); }, grain, Utils.CalculateIdHash(serviceName)); Assert.IsInstanceOfType(cast, typeof(IGeneratorTestGrain)); }
public void LogOff_LogsOutAndRedirects() { // Arrange AccountController controller = GetAccountController(); // Act ActionResult result = controller.LogOff(); // Assert Assert.IsInstanceOfType(result, typeof(RedirectToRouteResult)); RedirectToRouteResult redirectResult = (RedirectToRouteResult)result; Assert.AreEqual("Home", redirectResult.RouteValues["controller"]); Assert.AreEqual("Index", redirectResult.RouteValues["action"]); Assert.IsTrue(((MockFormsAuthenticationService)controller.FormsService).SignOut_WasCalled); }
private void RunGrainReferenceSerializationTest <TGrainInterface>() { var counters = new List <CounterStatistic> { CounterStatistic.FindOrCreate(StatisticNames.SERIALIZATION_BODY_FALLBACK_SERIALIZATION), CounterStatistic.FindOrCreate(StatisticNames.SERIALIZATION_BODY_FALLBACK_DESERIALIZATION), CounterStatistic.FindOrCreate(StatisticNames.SERIALIZATION_BODY_FALLBACK_DEEPCOPIES) }; // Get the (generated) grain reference implementation for a particular grain interface type. var grainReference = this.GetGrainReference <TGrainInterface>(); // Get the current value of each of the fallback serialization counters. var initial = counters.Select(_ => _.GetCurrentValue()).ToList(); // Serialize and deserialize the grain reference. var writer = new BinaryTokenStreamWriter(); SerializationManager.Serialize(grainReference, writer); var deserialized = SerializationManager.Deserialize(new BinaryTokenStreamReader(writer.ToByteArray())); var copy = (GrainReference)SerializationManager.DeepCopy(deserialized); // Get the final value of the fallback serialization counters. var final = counters.Select(_ => _.GetCurrentValue()).ToList(); // Ensure that serialization was correctly performed. Assert.IsInstanceOfType( deserialized, grainReference.GetType(), "Deserialized GrainReference type should match original type"); var deserializedGrainReference = (GrainReference)deserialized; Assert.IsTrue( deserializedGrainReference.GrainId.Equals(grainReference.GrainId), "Deserialized GrainReference should have same GrainId as original value."); Assert.IsInstanceOfType(copy, grainReference.GetType(), "DeepCopy GrainReference type should match original type"); Assert.IsTrue( copy.GrainId.Equals(grainReference.GrainId), "DeepCopy GrainReference should have same GrainId as original value."); // Check that the counters have not changed. var initialString = string.Join(",", initial); var finalString = string.Join(",", final); Assert.AreEqual(initialString, finalString, "GrainReference serialization should not use fallback serializer."); }