Beispiel #1
0
 public LocationDataImporter(IDataServiceFactory dataServiceFactory)
 {
     _locationServiceProxy = dataServiceFactory.CreateLocationDataService(DataSourceType.Remote);
     _snapshotServiceProxy = dataServiceFactory.CreateLocationSnapshotDataService(DataSourceType.Remote);
     _snapshotService      = dataServiceFactory.CreateLocationSnapshotDataService(DataSourceType.Local);
     _pictureServiceProxy  = dataServiceFactory.CreatePictureService(DataSourceType.Remote);
     _pictureService       = dataServiceFactory.CreatePictureService(DataSourceType.Local);
 }
        private void SetUp()
        {
            _dataServiceFactory   = Substitute.For <IDataServiceFactory>();
            _locationServiceProxy = Substitute.For <ILocationDataService>();
            _snapshotServiceProxy = Substitute.For <ILocationSnapshotDataService>();
            _snapshotService      = Substitute.For <ILocationSnapshotDataService>();
            _pictureServiceProxy  = Substitute.For <IPictureService>();
            _pictureService       = Substitute.For <IPictureService>();

            _dataServiceFactory.CreateLocationDataService(DataSourceType.Remote).Returns(_locationServiceProxy);
            _dataServiceFactory.CreateLocationSnapshotDataService(DataSourceType.Remote).Returns(_snapshotServiceProxy);
            _dataServiceFactory.CreateLocationSnapshotDataService(DataSourceType.Local).Returns(_snapshotService);
            _dataServiceFactory.CreatePictureService(DataSourceType.Remote).Returns(_pictureServiceProxy);
            _dataServiceFactory.CreatePictureService(DataSourceType.Local).Returns(_pictureService);

            _locationToImport = new Location
            {
                Id   = 1,
                Name = "Barcelona"
            };
            _snapshotsToImport = new List <LocationSnapshot>
            {
                new LocationSnapshot
                {
                    Id              = 1,
                    LocationId      = 1,
                    PictureFileName = "Barcelona1.jpg"
                },
                new LocationSnapshot
                {
                    Id              = 2,
                    LocationId      = 1,
                    PictureFileName = "Barcelona2.jpg"
                },
            };

            _snapshotService.GetSnapshotsByLocationIdAsync(Arg.Any <int>())
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <IEnumerable <LocationSnapshot> >();
                tcs.SetResult(_snapshotsToImport);
                return(tcs.Task);
            });

            _pictureData = new byte[] { 1, 2, 3, 4 };
            _pictureService.GetSnapshotContentAsync(Arg.Any <LocationSnapshot>())
            .Returns(_ =>
            {
                var tcs = new TaskCompletionSource <byte[]>();
                tcs.SetResult(_pictureData);
                return(tcs.Task);
            });
        }