public void SetUp() { fixture = new Fixture(); FixtureUtils.ConfigureFixtureForCreateSchedule(fixture); freshDays = new List <ISchedule>(); for (int i = 0; i < 4; i++) { freshDays.Add(FixtureUtils.CreateFixtureDaySchedule(3, 1, fixture)); } groups = new List <IScheduleGroup>(); freshDays.ForEach(d => groups.Add(d.ScheduleGroups.First())); storedDays = new List <ISchedule>(); for (int i = 0; i < 3; i++) { storedDays.Add(FixtureUtils.CreateFixtureDaySchedule(3, 1, fixture)); } storedDays.Select((d, i) => d.ScheduleGroups = new[] { groups[i] }).ToList(); infoProviderFake = A.Fake <IScheduleInfoProvider>(); A.CallTo(() => infoProviderFake.GetSchedules(null, default(DayOfWeek))).WithAnyArguments() .Returns(freshDays); storageFake = A.Fake <ISchedulesStorage>(); A.CallTo(() => storageFake.GetSchedules(null, default(DayOfWeek))).WithAnyArguments().Returns(storedDays); monitorFake = A.Fake <IGroupsMonitor>(); A.CallTo(() => monitorFake.AvailableGroups).Returns(groups); service = new ScheduleService(storageFake, monitorFake, infoProviderFake, new DefaultEventArgsFactory(), new SchElemsMerger(new DefaultSchElemsFactory())); }
public void WithSource_FailedResultWith2Errors_ShouldUpdateOnlyNeededSource() { var errorSource1 = SourceBuilder.BuildErrorSource <FakeCreateCommand>(c => c.AggregateRootId); var errorSource2 = SourceBuilder.BuildErrorSource <FakeCreateCommand>(c => c.SomeArray[0].SomeInternalArray[0].SomeInt); var executionErrors = new[] { new ExecutionError(new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String()), errorSource1), new ExecutionError(new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String()), errorSource2) }; var result = new CreationResult <DummyEntry>(executionErrors) .WithSource <DummyEntry, FakeCreateCommand>(c => c.SomeArray[3]); result.Entry.Should().BeNull(); var internalErrors = result.Errors.ToArray(); internalErrors[0].CodeInfo.Should().Be(executionErrors[0].CodeInfo); internalErrors[0].Code.Should().Be(executionErrors[0].Code); internalErrors[0].Message.Should().Be(executionErrors[0].Message); internalErrors[0].Source.Should().Be(errorSource1); internalErrors[1].CodeInfo.Should().Be(executionErrors[1].CodeInfo); internalErrors[1].Code.Should().Be(executionErrors[1].Code); internalErrors[1].Message.Should().Be(executionErrors[1].Message); internalErrors[1].Source.Should().Be("FakeCreateCommand.SomeArray.3.SomeInternalArray.0.SomeInt"); }
public void LoadKeyIntoRegisterTest() { // Arrange var sut = this.GetDefaultOpcodeProcessor(); var machineState = FixtureUtils.DefaultMachineState(); machineState.ProgramCounter = 0x402; machineState.CurrentOpcode = 0xF40A; machineState.VRegisters[0x4] = 0x0; machineState.Keys.SetAll(false); // Act sut.LoadKeyIntoRegister(machineState); // Assert Assert.Equal(machineState.VRegisters[0x4], 0x0); Assert.Equal(machineState.ProgramCounter, 0x400); // Arrange 2nd time, simulate key pressed machineState.Keys[0x3] = true; machineState.ProgramCounter = 0x402; // Act sut.LoadKeyIntoRegister(machineState); // Assert Assert.Equal(machineState.VRegisters[0x4], 0x3); Assert.Equal(machineState.ProgramCounter, 0x402); }
public void Constructor_Always_SetsValue() { var value = FixtureUtils.String(); new SuccessfulValueResult(value).Value.Should().Be(value); new SuccessfulValueResult(value).Success.Should().BeTrue(); }
public void Failed_WithErrorCode_ReturnsResultWithSameErrorCode() { var errorCode = new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String()); var expectedError = new ExecutionError(errorCode); CreationResult.Failed <DummyEntry>(errorCode) .Should().BeEquivalentTo(new CreationResult <DummyEntry>(expectedError)); }
public void ErrorCodeInfo_FromCode_Serializable() { var code = FixtureUtils.String(); var errorCodeInfo = SerializeDeserialize(new ErrorCodeInfo(code)); errorCodeInfo.Should().BeEquivalentTo(new ErrorCodeInfo(code)); }
public void TwoErrorCodes_CodesAreEqual_ErrorCodesAreEqual() { var code = FixtureUtils.String(); var message1 = FixtureUtils.String(); var message2 = FixtureUtils.String(); new ErrorCodeInfo(code, message1).Equals(new ErrorCodeInfo(code, message2)) .Should().BeTrue(); }
public async Task InitializeAsync() { var webHostUrl = FixtureUtils.IsRunningInContainer ? FixtureUtils.GetLocalIPAddress() : "127.0.0.1"; var settings = new LambdaTestHostSettings(() => new TestLambdaContext()) { WebHostUrl = $"http://{webHostUrl}:0", ConfigureLogging = logging => { logging.AddXUnit(_outputHelper); logging.SetMinimumLevel(LogLevel.Debug); } }; settings.AddFunction(new LambdaFunctionInfo( nameof(SimpleLambdaFunction), typeof(SimpleLambdaFunction), nameof(SimpleLambdaFunction.FunctionHandler))); _lambdaTestHost = await LambdaTestHost.Start(settings); var lambdaInvokeEndpoint = FixtureUtils.GetLambdaInvokeEndpoint(_outputHelper, _lambdaTestHost); _stepFunctionsLocal = new Builder() .UseContainer() .WithName("lambda-testhost-stepfunctions") .UseImage("amazon/aws-stepfunctions-local:latest") .WithEnvironment($"LAMBDA_ENDPOINT={lambdaInvokeEndpoint}") .ReuseIfExists() .ExposePort(0, ContainerPort) .Build() .Start(); var exposedPort = _stepFunctionsLocal .GetConfiguration() .NetworkSettings .Ports.First() .Value.First() .HostPort; var stepFunctionsServiceUrl = new UriBuilder($"http://localhost:{exposedPort}"); if (FixtureUtils.IsRunningInContainer) { var host = _stepFunctionsLocal .GetConfiguration() .NetworkSettings .IPAddress; stepFunctionsServiceUrl.Host = host; stepFunctionsServiceUrl.Port = ContainerPort; } _stepFunctionsServiceUrl = stepFunctionsServiceUrl.Uri; }
public void ErrorCodeInfo_FromPrefixAndCodeAndMessage_Serializable() { var prefix = FixtureUtils.String(); var code = FixtureUtils.String(); var message = FixtureUtils.String(); var errorCodeInfo = SerializeDeserialize(new ErrorCodeInfo(prefix, code, message)); errorCodeInfo.Should().BeEquivalentTo(new ErrorCodeInfo(prefix, code, message)); }
public void ExistingJsonData_Always_Deserializable() { var code = FixtureUtils.String(); var message = FixtureUtils.String(); var json = $@"{{ ""Code"": ""{code}"", ""Message"": ""{message}"" }}"; var errorCodeInfo = JsonConvert.DeserializeObject <ErrorCodeInfo>(json); errorCodeInfo.Should().BeEquivalentTo(new ErrorCodeInfo(code, message)); }
public void ValidationFailed_WithMessage_CreatesFailedResult() { var errorCodeInfo = CoreErrorCodes.UnhandledError; var errorMessage = FixtureUtils.String(); var failedResult = ValidationFailed(errorCodeInfo, errorMessage); failedResult.CodeInfo.Should().Be(CoreErrorCodes.ValidationFailed); failedResult.Details.Single().CodeInfo.Should().Be(CoreErrorCodes.UnhandledError); failedResult.Details.Single().Message.Should().Be(errorMessage); }
private FakeAggregateRoot SetupAggregateRootWithEvents() { var id = Unified.NewCode(); var executionContext = new AggregateExecutionContext(Fixtures.Pipelines.FakeCreateCommand()); var aggregateRoot = new FakeAggregateRoot(id, executionContext); aggregateRoot.Create(FixtureUtils.String()); aggregateRoot.Update(FixtureUtils.String()); return(aggregateRoot); }
public void CreateFromSource2_Always_CopiesMessageCorrelationData() { var integrationEvent = Fixtures.Pipelines.FakeCreatedIntegrationEvent(); var signal = QueryModelChangedSignal.CreateFromSource( integrationEvent, Unified.NewCode(), typeof(int), FixtureUtils.FromEnum <QueryModelChangeOperation>()); signal.Should().BeEquivalentTo(integrationEvent, options => options.ForMessage()); }
public void ClearScreenTest() { // Arrange var sut = this.GetDefaultOpcodeProcessor(); var machineState = FixtureUtils.DefaultMachineState(); // Act sut.ClearScreen(machineState); // Assert Assert.True(!machineState.Graphics.Cast <bool>().Any(x => x)); }
public void JumpToRoutineAtAdressTest() { // Arrange var sut = this.GetDefaultOpcodeProcessor(); var machineState = FixtureUtils.DefaultMachineState(); // Act sut.JumpToRoutineAtAdress(machineState); // Assert Assert.True(!machineState.Stack.Any()); }
public void ValidationFailed_WithCollectionOfErrors_ReturnResultWithSameInternalErrors() { var executionErrors = new[] { new ExecutionError(new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String())), new ExecutionError(new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String())) }; var result = FailedResult.ValidationFailed(executionErrors); result.CodeInfo.Should().BeEquivalentTo(CoreErrorCodes.ValidationFailed); result.Details.Should().BeEquivalentTo <ExecutionError>(executionErrors); }
public void Constructor_Always_CreatesNotification() { var isPrivate = FixtureUtils.Bool(); var integrationEvent = Fixtures.Pipelines.FakeCreatedIntegrationEvent(); var signal = Fixtures.Pipelines.FakeQueryModelCreatedSignal <int>(integrationEvent); var notification = new QueryModelChangedNotification(signal) { IsPrivate = isPrivate }; notification.Signal.Should().BeEquivalentTo(signal); notification.IsPrivate.Should().Be(isPrivate); }
public void Constructor_WithErrors_CreatesRsultWithSameErrors() { var executionErrors = new[] { new ExecutionError(new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String())), new ExecutionError(new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String())) }; var result = new CreationResult <DummyEntry>(executionErrors); var(errors, entry) = result; entry.Should().BeNull(); errors.Should().BeEquivalentTo <ExecutionError>(executionErrors); }
public void LoadIntoIndexRegisterTest() { // Arrange var sut = this.GetDefaultOpcodeProcessor(); var machineState = FixtureUtils.DefaultMachineState(); machineState.CurrentOpcode = 0xA327; // Act sut.LoadIntoIndexRegister(machineState); // Assert Assert.Equal(machineState.IndexRegister, 0x327); }
public void JumpTest() { // Arrange var sut = this.GetDefaultOpcodeProcessor(); var machineState = FixtureUtils.DefaultMachineState(); machineState.CurrentOpcode = 0x1234; // Act sut.Jump(machineState); // Assert Assert.Equal(machineState.ProgramCounter, 0x234); }
public void Constructor_Always_UpdatesProperties() { var queryModelId = Unified.NewCode(); var queryModelVersion = FixtureUtils.Int(); var queryModelType = typeof(int); var operation = FixtureUtils.FromEnum <QueryModelChangeOperation>(); var signal = new QueryModelChangedSignal(queryModelId, queryModelVersion, queryModelType, operation); signal.QueryModelId.Should().Be(queryModelId); signal.QueryModelVersion.Should().Be(queryModelVersion); signal.QueryModelType.Should().Be(queryModelType); signal.Operation.Should().Be(operation); }
public async Task SaveAsync_HasEvents_Stores() { var id = Unified.NewCode(); var executionContext = new AggregateExecutionContext(Fixtures.Pipelines.FakeCreateCommand()); var aggregateRoot = new FakeAggregateRoot(id, executionContext); aggregateRoot.Create(FixtureUtils.String()); aggregateRoot.Update(FixtureUtils.String()); await store.SaveAsync(aggregateRoot); var events = await store.GetAsync(aggregateRoot.Id, 0); events.Should().BeEquivalentTo(aggregateRoot.Events, options => options.ForMessage()); }
public void AddValueIntoRegisterTest() { // Arrange var sut = this.GetDefaultOpcodeProcessor(); var machineState = FixtureUtils.DefaultMachineState(); machineState.CurrentOpcode = 0x7630; machineState.VRegisters[6] = 0x25; // Act sut.AddValueIntoRegister(machineState); // Assert Assert.Equal(machineState.VRegisters[6], 0x30 + 0x25); }
public void QueryModelChangedSignal_Always_SerializedCorrectly() { var signal = new QueryModelChangedSignal(Unified.NewCode(), FixtureUtils.Int(), typeof(int), FixtureUtils.FromEnum <QueryModelChangeOperation>()) { CorrelationId = Unified.NewCode(), AggregateRootId = Unified.NewCode(), Metadata = { [MetadataKey.UserId] = Unified.NewCode() }, Actor = { IdentityId = Unified.NewCode(), UserId = Unified.NewCode(), IsProcessManager = true } }; var json = JsonConvert.SerializeObject(signal); var deserialized = JsonConvert.DeserializeObject <QueryModelChangedSignal>(json); deserialized.Should().BeEquivalentTo(signal); }
public void LoadRegisterIntoRegisterTest() { // Arrange var sut = this.GetDefaultOpcodeProcessor(); var machineState = FixtureUtils.DefaultMachineState(); machineState.CurrentOpcode = 0x8230; machineState.VRegisters[3] = 0x80; // Act sut.LoadRegisterIntoRegister(machineState); // Assert Assert.Equal(machineState.VRegisters[2], 0x80); }
public void ReturnFromSubRoutineTest() { // Arrange var sut = this.GetDefaultOpcodeProcessor(); var machineState = FixtureUtils.DefaultMachineState(); machineState.Stack.Push(0x305); // Act sut.ReturnFromSubRoutine(machineState); // Assert Assert.Equal(machineState.ProgramCounter, 0x305); Assert.True(machineState.Stack.Count == 0); }
public void JumpToV0PlusImmediateTest() { // Arrange var sut = this.GetDefaultOpcodeProcessor(); var machineState = FixtureUtils.DefaultMachineState(); machineState.CurrentOpcode = 0xB327; machineState.VRegisters[0x0] = 0x1111; // Act sut.JumpToV0PlusImmediate(machineState); // Assert Assert.Equal(machineState.ProgramCounter, 0x1111 + 0x0327); }
public void LoadRandomIntoRegisterTest() { // Arrange var sut = this.GetDefaultOpcodeProcessor(); var machineState = FixtureUtils.DefaultMachineState(); machineState.CurrentOpcode = 0xC320; machineState.VRegisters[3] = 0x1111; // Act sut.LoadRandomIntoRegister(machineState); // Assert Assert.NotEqual(machineState.VRegisters[3], 0x1111); }
public void CreateWithInternal_Creates_2LevelError() { var externalCode = new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String()); var internalCode = new ErrorCodeInfo(nameof(Core), FixtureUtils.String(), FixtureUtils.String()); var result = FailedResult.Create(externalCode, internalCode); result.Code.Should().Be(externalCode.Code); result.Message.Should().Be(externalCode.Message); var internalError = result.Details.Single(); internalError.Message.Should().Be(internalCode.Message); internalError.Code.Should().Be(internalCode.Code); }
public void Deserialize_EnumObject_WorksCorrectly() { var source = new EnumObject { TestEnumProperty = FixtureUtils.FromEnum <TestEnum>(), ChildEnumObjectProperty = new ChildEnumObject { TestEnumProperty = FixtureUtils.FromEnum <TestEnum>() } }; var serialized = AzureTableSerializer.Serialize(source); var deserialized = AzureTableSerializer.Deserialize <EnumObject>(Entity(serialized)); deserialized.Should().BeEquivalentTo(source, options => options .Excluding(o => o.Timestamp)); }