Skip to content

Commit

Permalink
Fix broken specs
Browse files Browse the repository at this point in the history
  • Loading branch information
woksin committed Feb 10, 2025
1 parent 47fa364 commit 4cad852
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Source/Kernel/Grains.Specs/Jobs/SomeJobRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Cratis.Chronicle.Concepts.Jobs;
namespace Cratis.Chronicle.Grains.Jobs;

public record SomeJobRequest(int SomeNumber);
public record SomeJobRequest(int SomeNumber) : IJobRequest;
3 changes: 2 additions & 1 deletion Source/Kernel/Grains.Specs/Jobs/for_Job/given/SomeRequest.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Cratis.Chronicle.Concepts.Jobs;
namespace Cratis.Chronicle.Grains.Jobs.for_Job.given;

public class SomeRequest;
public class SomeRequest : IJobRequest;
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class the_manager : Specification
protected IEventStoreNamespaceStorage _namespaceStorage;
protected IJobStorage _jobStorage;
protected IJobStepStorage _jobStepStorage;
protected IJobTypes _jobTypes;

protected List<JobState> _storedJobs;

Expand All @@ -34,11 +35,13 @@ async Task Establish()
_namespaceStorage = Substitute.For<IEventStoreNamespaceStorage>();
_jobStorage = Substitute.For<IJobStorage>();
_jobStepStorage = Substitute.For<IJobStepStorage>();
_jobTypes = Substitute.For<IJobTypes>();

_storage.GetEventStore(Arg.Any<EventStoreName>()).Returns(_eventStoreStorage);
_eventStoreStorage.GetNamespace(Arg.Any<EventStoreNamespaceName>()).Returns(_namespaceStorage);
_namespaceStorage.Jobs.Returns(_jobStorage);
_namespaceStorage.JobSteps.Returns(_jobStepStorage);
_jobTypes.GetClrTypeFor(Arg.Any<JobType>()).Returns(Result.Failed<Type, IJobTypes.GetClrTypeForError>(IJobTypes.GetClrTypeForError.CouldNotFindType));

_jobStorage.GetJobs(Arg.Any<JobStatus[]>()).Returns(_ => Task.FromResult(Catch.Success<IImmutableList<JobState>>([.. _storedJobs])));
_jobStorage.GetJob(Arg.Any<JobId>()).Returns(callInfo => Task.FromResult(
Expand All @@ -48,6 +51,7 @@ async Task Establish()
_jobStepStorage.RemoveAllForJob(Arg.Any<JobId>()).Returns(Task.FromResult(Catch.Success()));
_silo.AddService(_storage);
_silo.AddService(NullLogger<JobsManager>.Instance);
_silo.AddService(_jobTypes);
var loggerFactory = Substitute.For<ILoggerFactory>();
_silo.AddService(loggerFactory);
_managerKey = new ("event-store", "namespace");
Expand All @@ -63,6 +67,7 @@ protected Mock<TJob> AddJob<TJob>(JobId id)
Id = id
};
_storedJobs.Add(state);
_jobTypes.GetClrTypeFor(state.Type).Returns(Result.Success<Type, IJobTypes.GetClrTypeForError>(typeof(TJob)));
return _silo.AddProbe<TJob>(state.Id, keyExtension: new JobKey(_managerKey.EventStore, _managerKey.Namespace));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Cratis.Chronicle.Concepts;
using Cratis.Chronicle.Concepts.Jobs;
using Moq;
namespace Cratis.Chronicle.Grains.Jobs.for_JobsManager;
Expand All @@ -14,6 +15,7 @@ void Establish()
{
_jobId = Guid.Parse("24ff9a76-a590-49b7-847d-28fcc9bf1024");
_job = AddJob<INullJobWithSomeRequest>(_jobId);
_job.Setup(_ => _.Stop()).ReturnsAsync(Result.Success<JobError>());
}

Task Because() => _manager.Delete(_jobId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Cratis.Chronicle.Concepts;
using Cratis.Chronicle.Concepts.Jobs;
using Moq;
namespace Cratis.Chronicle.Grains.Jobs.for_JobsManager;
Expand All @@ -18,6 +19,8 @@ void Establish()
_secondJobId = Guid.Parse("d090f5e6-5a6a-43b1-8580-4973e3c69521");
_firstJob = AddJob<INullJobWithSomeRequest>(_firstJobId);
_secondJob = AddJob<INullJobWithSomeRequest>(_secondJobId);
_firstJob.Setup(_ => _.Resume()).ReturnsAsync(Result<ResumeJobSuccess, ResumeJobError>.Success(ResumeJobSuccess.Success));
_secondJob.Setup(_ => _.Resume()).ReturnsAsync(Result<ResumeJobSuccess, ResumeJobError>.Success(ResumeJobSuccess.Success));
}

Task Because() => _manager.Rehydrate();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Cratis.Chronicle.Concepts;
using Cratis.Chronicle.Concepts.Jobs;
using Moq;
namespace Cratis.Chronicle.Grains.Jobs.for_JobsManager;
Expand All @@ -14,6 +15,7 @@ void Establish()
{
_jobId = Guid.Parse("24ff9a76-a590-49b7-847d-28fcc9bf1024");
_job = AddJob<INullJobWithSomeRequest>(_jobId);
_job.Setup(_ => _.Resume()).ReturnsAsync(Result<ResumeJobSuccess, ResumeJobError>.Success(ResumeJobSuccess.Success));
}

Task Because() => _manager.Resume(_jobId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Cratis. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Cratis.Chronicle.Concepts;
using Cratis.Chronicle.Concepts.Jobs;
using Moq;
namespace Cratis.Chronicle.Grains.Jobs.for_JobsManager;
Expand All @@ -14,6 +15,7 @@ void Establish()
{
_jobId = Guid.Parse("24ff9a76-a590-49b7-847d-28fcc9bf1024");
_job = AddJob<INullJobWithSomeRequest>(_jobId);
_job.Setup(_ => _.Stop()).ReturnsAsync(Result.Success<JobError>());
}

Task Because() => _manager.Stop(_jobId);
Expand Down

0 comments on commit 4cad852

Please sign in to comment.