public void TestMultipleActorsForSingleActorId()
        {
            var sharedId = new ActorId(Guid.NewGuid());

            //mock out the called actors
            var statefulActorSvc = MockActorServiceFactory.CreateActorServiceForActor <MockTestStatefulActor>(
                (service, actorId) => new MockTestStatefulActor(service, actorId));
            var reminderActorService = MockActorServiceFactory.CreateActorServiceForActor <MockReminderTimerActor>(
                (service, actorId) => new MockReminderTimerActor(service, actorId));

            var statefulActor = statefulActorSvc.Activate(sharedId);
            var reminderActor = reminderActorService.Activate(sharedId);

            //prepare the service:
            var mockProxyFactory = new MockActorProxyFactory();

            mockProxyFactory.RegisterActor(statefulActor);
            mockProxyFactory.RegisterActor(reminderActor);

            //act:
            var a1 = mockProxyFactory.CreateActorProxy <IMyStatefulActor>(sharedId);
            var a2 = mockProxyFactory.CreateActorProxy <IReminderTimerActor>(sharedId);

            //assert:
            Assert.AreSame(typeof(MockTestStatefulActor), a1.GetType());
            Assert.AreSame(typeof(MockReminderTimerActor), a2.GetType());
        }
        public async Task TestServiceProxyFactory()
        {
            //mock out the called service

            var mockProxyFactory = new MockActorProxyFactory();

            mockProxyFactory.MissingActor += MockProxyFactory_MisingActorId;


            //prepare the actor:
            Func <ActorService, ActorId, ActorBase> actorFactory = (service, actorId) => new ActorCallerActor(service, actorId, mockProxyFactory);
            var svc   = MockActorServiceFactory.CreateActorServiceForActor <ActorCallerActor>(actorFactory);
            var actor = svc.Activate(ActorId.CreateRandom());

            //act:
            await actor.InsertAsync("test", new Payload("some other value"));

            //check if the other actor was called
            var statefulActorId = await actor.StateManager.GetStateAsync <ActorId>(ActorCallerActor.ChildActorIdKeyName);

            var statefulActor = mockProxyFactory.CreateActorProxy <IMyStatefulActor>(ActorCallerActor.CalledServiceName, statefulActorId);

            var payload = await((MyStatefulActor)statefulActor).StateManager.GetStateAsync <Payload>("test");

            //assert:
            Assert.AreEqual("some other value", payload.Content);
        }
Beispiel #3
0
        public async Task TestSubscribe_Doesnt_CrashAsync()
        {
            //var service = new CustomActorService(MockStatefulServiceContextFactory.Default, ActorTypeInformation.Get(typeof(MyStatefulActor)));
            //var factory = new MockActorServiceRemotingClientFactory(service);
            //var proxyFactory = new ActorProxyFactory(callbackClient => factory)

            var guid = Guid.NewGuid();
            var id   = new ActorId(guid);
            Func <ActorService, ActorId, ActorBase> factory = (service, actorId) => new ExampleActorMock(service, actorId);
            var svc   = MockActorServiceFactory.CreateActorServiceForActor <ExampleActorMock>(factory);
            var actor = svc.Activate(id);

            var mockProxyFactory = new MockActorProxyFactory();

            mockProxyFactory.RegisterActor(actor);

            var eventSubscriptionHelper = new MockActorEventSubscriptionHelper();
            var exampleService          = new ExampleClient(MockStatefulServiceContextFactory.Default, new MockReliableStateManager(),
                                                            eventSubscriptionHelper, mockProxyFactory);
            await exampleService.DoSomething(guid, "message text");

            Assert.IsTrue(eventSubscriptionHelper.IsSubscribed <IExampleEvents>(exampleService));
            Assert.IsFalse(IsSuccess);
            //Subscribe doesn't crash the test, but the Event is not really fired and processed at this time
        }
Beispiel #4
0
        public static TestContext WithHappyPath()
        {
            var testContext = new TestContext();

            testContext.TelemetryClient = new TelemetryClient(new TelemetryConfiguration("", testContext.MockTelemetryChannel));
            testContext.Actors          = Enumerable.Range(0, 10).Select(x => Guid.NewGuid()).Select(x =>
            {
                var actorProxyFactory       = new MockActorProxyFactory();
                var mockServiceProxyFactory = new MockServiceProxyFactory();
                var actorServiceForActor    = MockActorServiceFactory.CreateActorServiceForActor <Instance>();
                var instance = new Instance(actorServiceForActor, new ActorId(x), testContext.ClusterClient.Object,
                                            testContext.TelemetryClient);
                return(instance);
            }).ToList();

            var setupSequentialResult = testContext.GuidGetter.SetupSequence(x => x.GetAGuid());

            foreach (var actor in testContext.Actors)
            {
                setupSequentialResult.Returns(actor.Id.GetGuidId());
                testContext.MockActorProxyFactory.RegisterActor(actor);
            }
            testContext.PoolActorService = CreatePoolActorService(testContext.TelemetryClient, testContext.MockActorProxyFactory,
                                                                  testContext.GuidGetter.Object);
            testContext.Pool = testContext.PoolActorService.Activate(new ActorId("fabric:/myapplicationname/myservicetypename"));
            return(testContext);
        }
        public void TestMissingActorNotCreatedInEventHandler()
        {
            var mockProxyFactory = new MockActorProxyFactory();
            var actorId          = ActorId.CreateRandom();
            var instance         = mockProxyFactory.CreateActorProxy <IMyStatefulActor>(actorId);

            Assert.IsNull(instance);
        }
        public void TestMissingActorCreatedInEventHandler()
        {
            var mockProxyFactory = new MockActorProxyFactory();

            mockProxyFactory.MissingActor += MockProxyFactory_MisingActorId;
            var actorId  = ActorId.CreateRandom();
            var instance = mockProxyFactory.CreateActorProxy <IMyStatefulActor>(actorId);

            Assert.IsInstanceOfType(instance, typeof(IMyStatefulActor));
        }
        public async Task CanAddMoreHandlersDynamically(string eventName, int messageCount, int expectedHandlerId)
        {
            //create mocked handlers based on the amount of messages passed in to the test
            var mockActorProxyFactory = new MockActorProxyFactory();

            for (var i = 0; i <= messageCount; i++)
            {
                mockActorProxyFactory.RegisterActor(CreateMockEventHandlerActor(new ActorId($"{eventName}-{i + 1}")));
            }

            //return messages up to the limit of the test requirements
            var count = 0;

            _mockMessageProvider.Setup(s => s.ReceiveAsync(
                                           It.IsAny <int>(),
                                           It.IsAny <TimeSpan>())).ReturnsAsync(() =>
            {
                if (count >= messageCount)
                {
                    return(new List <Message>());
                }
                count++;
                return(CreateMessage(eventName));
            });

            var mockServiceBusProvider = new Mock <IServiceBusManager>();

            mockServiceBusProvider.Setup(s => s.CreateAsync(
                                             It.IsAny <string>(),
                                             It.IsAny <string>(),
                                             It.IsAny <string>(),
                                             It.IsAny <string>()));

            mockServiceBusProvider.Setup(s => s.CreateMessageReceiver(
                                             It.IsAny <string>(),
                                             It.IsAny <string>(),
                                             It.IsAny <string>(),
                                             It.IsAny <bool>())).Returns(_mockMessageProvider.Object);

            mockServiceBusProvider.Setup(s => s.GetLockToken(It.IsAny <Message>())).Returns(Guid.NewGuid().ToString);

            var service = new EventReaderService.EventReaderService(
                _context,
                _stateManager,
                _mockedBigBrother,
                mockServiceBusProvider.Object,
                mockActorProxyFactory,
                _config);

            var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(10));
            await service.InvokeRunAsync(cancellationTokenSource.Token);

            Assert.Equal(expectedHandlerId, service.HandlerCount);
        }
        public void TestMissingActorSecondTypeCreatedInEventHandler()
        {
            var mockProxyFactory = new MockActorProxyFactory();

            mockProxyFactory.MissingActor += MockProxyFactory_MisingActor_TwoTypes;
            var actorId   = ActorId.CreateRandom();
            var instance1 = mockProxyFactory.CreateActorProxy <IMyStatefulActor>(actorId);
            var instance2 = mockProxyFactory.CreateActorProxy <IReminderTimerActor>(actorId);

            Assert.IsInstanceOfType(instance1, typeof(IMyStatefulActor));
            Assert.IsInstanceOfType(instance2, typeof(IReminderTimerActor));
        }
 public EventReaderTests()
 {
     _context = CustomMockStatefulServiceContextFactory.Create(
         ServiceNaming.EventReaderServiceType,
         ServiceNaming.EventReaderServiceFullUri("test.type", "subA"),
         Encoding.UTF8.GetBytes(EventReaderInitData.GetReaderInitDataAsString("test.type", "subA")), replicaId: (new Random(int.MaxValue)).Next());
     _mockActorProxyFactory = new MockActorProxyFactory();
     _stateManager          = new MockReliableStateManager();
     _config              = new ConfigurationSettings();
     _mockedBigBrother    = new Mock <IBigBrother>().Object;
     _mockMessageProvider = new Mock <IMessageReceiver>();
 }
Beispiel #10
0
        public MockFabricRuntime(string applicationName)
        {
            ApplicationName = applicationName;
            _stateManager   = new MockReliableStateManager();

            var serviceProxyFactory = new MockServiceProxyFactory(this);
            var actorProxyFactory   = new MockActorProxyFactory(this);

            _serviceProxyFactory = serviceProxyFactory;
            _actorProxyFactory   = actorProxyFactory;

            FG.ServiceFabric.Services.Remoting.Runtime.Client.ServiceProxyFactory.SetInnerFactory((factory, serviceType) => _serviceProxyFactory);;
            FG.ServiceFabric.Actors.Client.ActorProxyFactory.SetInnerFactory((factory, serviceType, actorType) => _actorProxyFactory);;
        }
Beispiel #11
0
        static FixtureBase()
        {
            _messageDictionary = new Dictionary <string, string>();

            _actorProxyFactory   = new MockActorProxyFactory();
            _serviceProxyFactory = new MockServiceProxyFactory();

            var repositoryFactoryMock = new Mock <IRepositoryFactories>();

            var repositoryMock = new Mock <IMessageRepository>();

            repositoryMock.Setup(i => i.Send(It.IsAny <string>(), It.IsAny <string>())).Returns((string s, string y) => MockSendMessage(s, y));

            repositoryFactoryMock.Setup(f => f.CreateMessageRepository()).Returns(repositoryMock.Object);

            // setup repositories when you can
            _factories = repositoryFactoryMock.Object;
        }
        public async Task TestActorProxyFactory()
        {
            //mock out the called actor
            var id = new ActorId(ActorCallerService.CalledActorId);
            Func <ActorService, ActorId, ActorBase> actorFactory = (service, actorId) => new MockTestStatefulActor(service, id);
            var svc   = MockActorServiceFactory.CreateActorServiceForActor <MockTestStatefulActor>(actorFactory);
            var actor = svc.Activate(id);

            //prepare the service:
            var mockProxyFactory = new MockActorProxyFactory();

            mockProxyFactory.RegisterActor(actor);
            var serviceInstance = new ActorCallerService(MockStatelessServiceContextFactory.Default, mockProxyFactory);

            //act:
            await serviceInstance.CallActorAsync();

            //assert:
            Assert.IsTrue(actor.InsertAsyncCalled);
        }
Beispiel #13
0
 public void Cleanup()
 {
     _actorProxyFactory   = new MockActorProxyFactory();
     _serviceProxyFactory = new MockServiceProxyFactory();
 }
Beispiel #14
0
 public MyMockActorProxyFactoryWrapper()
 {
     _proxy = new MockActorProxyFactory();
 }