public async Task Should_Not_Record_Last_Sync_When_Failed()
        {
            _service1.Sync(_user).Returns(Task.FromResult(SyncResult.Failed("test error!")));
            _service2.Sync(_user).Returns(Task.FromResult(SyncResult.Success()));

            await _syncService.Sync(_user);

            _persistenceContextFactory.DidNotReceive().CreateFor <SyncInfo>();
        }
        public async Task Should_Return_Success_When_No_Errors()
        {
            _service1.Sync(_user).Returns(Task.FromResult(SyncResult.Success()));
            _service2.Sync(_user).Returns(Task.FromResult(SyncResult.Success()));

            var syncResult = await _syncService.Sync(_user);

            Assert.That(syncResult.HasErrors, Is.False);
        }
        public async Task Should_Return_Failure_When_Any_Of_The_Services_Fails()
        {
            _service1.Sync(_user).Returns(Task.FromResult(SyncResult.Success()));
            _service2.Sync(_user).Returns(Task.FromResult(SyncResult.Failed("test error")));

            var syncResult = await _syncService.Sync(_user);

            Assert.That(syncResult.HasErrors);
            Assert.That(syncResult.ErrorMessage, Is.EqualTo("test error"));
        }
        public async Task Should_Record_Last_Sync_When_Successful()
        {
            _service1.Sync(_user).Returns(Task.FromResult(SyncResult.Success()));
            _service2.Sync(_user).Returns(Task.FromResult(SyncResult.Success()));
            var currentTime = DateTimeOffset.UtcNow;

            _syncService.GetCurrentTimeFunc = () => currentTime;

            await _syncService.Sync(_user);

            _persistenceContextFactory.CreateFor <SyncInfo>().Received().Save(Arg.Is <SyncInfo>(s => s.LastSync == currentTime && s.ObjectId == "x"));
        }
        public async Task Should_Not_Execute_Subsequent_SyncServices_On_Failure()
        {
            _service1.Sync(_user).Returns(Task.FromResult(SyncResult.Failed("test error")));
            _service2.Sync(_user).Returns(Task.FromResult(SyncResult.Success()));

            var syncResult = await _syncService.Sync(_user);

            await _service2.DidNotReceive().Sync(_user);

            Assert.That(syncResult.HasErrors);
            Assert.That(syncResult.ErrorMessage, Is.EqualTo("test error"));
        }
Exemplo n.º 6
0
        public async Task <SyncResult> SyncJobsAsync(GameSave gameSave, GameModType modType, int selectedDlc)
        {
            var webApi         = new Ets2SyncApiHost();
            var syncJobsResult = await webApi.SyncJobs(gameSave, modType, selectedDlc);

            if (syncJobsResult.Result != SyncJobsResult.SyncResult.Success)
            {
                return(SyncResult.Fail(syncJobsResult.ErrorException));
            }

            await using var fileWriter = File.Create(gameSave.FilePath);
            await fileWriter.WriteAsync(syncJobsResult.SaveFileBytes);

            return(SyncResult.Success(syncJobsResult.SaveFileBytes));
        }
Exemplo n.º 7
0
        public async Task <SyncResult> Sync(User user)
        {
            await Task.Delay(TimeSpan.FromSeconds(3));

            return(SyncResult.Success());
        }