Ejemplo n.º 1
0
        protected override void AdditionalSetup()
        {
            var mockDispatcher = new MockDispatcher();

            Ioc.RegisterSingleton <IMvxViewDispatcher>(mockDispatcher);
            Ioc.RegisterSingleton <IMvxMainThreadDispatcher>(mockDispatcher);

            _mockUserInteraction = Ioc.RegisterNewMock <ICustomUserInteraction>();

            _fixture = new Fixture().Customize(new AutoMoqCustomization());

            _fixture.Register <IReachability>(() => Mock.Of <IReachability>(r => r.IsConnected() == true));

            _driver = new Core.Models.Driver()
            {
                LastName = "TestName", ID = Guid.NewGuid()
            };

            _trailer = new Core.Models.Trailer()
            {
                Registration = "TestRegistration", ID = Guid.NewGuid()
            };
            _trailerItemViewModel = new TrailerItemViewModel()
            {
                Trailer = _trailer
            };

            _infoService = _fixture.Create <InfoService>();
            _infoService.CurrentDriverID = _driver.ID;
            _fixture.Inject <IInfoService>(_infoService);

            _currentDriverRepository = new Mock <ICurrentDriverRepository>();
            _currentDriverRepository.Setup(cdr => cdr.GetByIDAsync(It.IsAny <Guid>())).ReturnsAsync(new CurrentDriver());
            _fixture.Inject <ICurrentDriverRepository>(_currentDriverRepository.Object);

            _applicationProfile = new ApplicationProfile {
                LastVehicleAndDriverSync = DateTime.Now
            };
            _applicationRepository = _fixture.InjectNewMock <IApplicationProfileRepository>();
            _applicationRepository.Setup(ar => ar.GetAllAsync()).ReturnsAsync(new List <ApplicationProfile>()
            {
                _applicationProfile
            });

            _trailerRepository = new Mock <ITrailerRepository>();
            _fixture.Inject <ITrailerRepository>(_trailerRepository.Object);

            var mockAuthenticationService = new Mock <IAuthenticationService>();

            mockAuthenticationService.Setup(m => m.AuthenticateAsync(It.IsAny <string>())).ReturnsAsync(new AuthenticationResult {
                Success = false
            });
            mockAuthenticationService.Setup(m => m.AuthenticateAsync(It.Is <string>(s => s == "9999"))).ReturnsAsync(new AuthenticationResult {
                Success = true, Driver = _driver
            });
            _fixture.Inject <IAuthenticationService>(mockAuthenticationService.Object);

            _fixture.Inject <IRepositories>(_fixture.Create <Repositories>());
        }
Ejemplo n.º 2
0
        protected override void AdditionalSetup()
        {
            var mockDispatcher = new MockDispatcher();

            Ioc.RegisterSingleton <IMvxViewDispatcher>(mockDispatcher);
            Ioc.RegisterSingleton <IMvxMainThreadDispatcher>(mockDispatcher);

            var mockUserInteraction = new Mock <ICustomUserInteraction>();

            Ioc.RegisterSingleton <ICustomUserInteraction>(mockUserInteraction.Object);

            _mockUserInteraction = new Mock <ICustomUserInteraction>();
            _mockUserInteraction.Setup(ui => ui.ConfirmAsync(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true);
            Ioc.RegisterSingleton <ICustomUserInteraction>(_mockUserInteraction.Object);

            _fixture = new Fixture().Customize(new AutoMoqCustomization());

            _fixture.Register <IReachability>(() => Mock.Of <IReachability>(r => r.IsConnected() == true));

            _trailer = new Core.Models.Trailer()
            {
                Registration = "TestRegistration", ID = Guid.NewGuid()
            };
            _trailerItemViewModel = new TrailerItemViewModel()
            {
                Trailer = _trailer
            };

            _infoService = _fixture.Create <InfoService>();
            _fixture.Inject <IInfoService>(_infoService);

            _mockMessenger = Ioc.RegisterNewMock <IMvxMessenger>();
            _mockMessenger.Setup(m => m.Unsubscribe <GatewayInstructionNotificationMessage>(It.IsAny <MvxSubscriptionToken>()));
            _mockMessenger.Setup(m => m.Subscribe(It.IsAny <Action <GatewayInstructionNotificationMessage> >(), It.IsAny <MvxReference>(), It.IsAny <string>())).Returns(_fixture.Create <MvxSubscriptionToken>());

            _navigationServiceMock = _fixture.InjectNewMock <INavigationService>();
            Ioc.RegisterSingleton <INavigationService>(_navigationServiceMock.Object);

            var repositories = _fixture.Create <IRepositories>();

            _fixture.Inject(repositories);
            _mockRepositories = Mock.Get(repositories);
            Ioc.RegisterSingleton <IRepositories>(_mockRepositories.Object);

            var applicationRepository = Mock.Of <IApplicationProfileRepository>(apr => apr.GetAllAsync() == Task.FromResult(_fixture.CreateMany <Core.Models.ApplicationProfile>()));

            _mockRepositories.Setup(r => r.ApplicationRepository).Returns(applicationRepository);
        }