public async Task GetLeftSeatCount_Ok() { const int maxCount = 10000; var state = TrainInfo.Create(Enumerable.Range(1000, 4).ToList(), maxCount); var claptrapDesign = ActorTestHelper.GetDesign(typeof(TrainGran)); using var mocker = claptrapDesign.CreateAutoMock("123", state); var actor = mocker.Create <TrainGran>(); var count = await actor.GetLeftSeatCountAsync(1000, 1001); count.Should().Be(maxCount); }
public void UpdateCount_StationNotFound() { using var mocker = AutoMock.GetStrict(); const int maxCount = 10000; var state = TrainInfo.Create(Enumerable.Range(1000, 4).ToList(), maxCount); mocker.Mock <IClaptrapGrainCommonService>() .Setup(x => x.ClaptrapAccessor.Claptrap.State.Data) .Returns(state); var grain = mocker.Create <TrainGran>(); grain.TrainId = 123; Assert.ThrowsAsync <StationNotFoundException>(() => grain.UpdateCountAsync(1000, 10000)); }
public async Task UpdateCount_Ok() { using var mocker = AutoMock.GetStrict(); const int maxCount = 10000; var state = TrainInfo.Create(Enumerable.Range(1000, 4).ToList(), maxCount); mocker.Mock <IClaptrapGrainCommonService>() .Setup(x => x.ClaptrapAccessor.Claptrap.State.Data) .Returns(state); mocker.MockEventHandling <UpdateCountEvent>(ClaptrapCodes.UpdateCount); var grain = mocker.Create <TrainGran>(); grain.TrainId = 123; await grain.UpdateCountAsync(1000, 1001); }
public async Task GetLeftSeatCount_Ok() { using var mocker = AutoMock.GetStrict(); const int maxCount = 10000; var state = TrainInfo.Create(Enumerable.Range(1000, 4).ToList(), maxCount); mocker.Mock <IClaptrapGrainCommonService>() .Setup(x => x.ClaptrapAccessor.Claptrap.State.Data) .Returns(state); var grain = mocker.Create <TrainGran>(); grain.TrainId = 123; var count = await grain.GetLeftSeatCountAsync(1000, 1001); count.Should().Be(maxCount); }
public int AddOrUpdateTrainInfo(TrainInfo traininfo, string keyValue) { int result = 0; if (string.IsNullOrEmpty(keyValue)) { TrainInfo model = new TrainInfo(); model.Create(); model.TrainTitle = traininfo.TrainTitle; model.Address = traininfo.Address; model.ApplyETime = traininfo.ApplyETime; model.ApplySTime = traininfo.ApplySTime; model.StartTime = traininfo.StartTime; model.EndTime = traininfo.EndTime; model.Content = traininfo.Content; model.PartNumber = 0; model.LimitNumber = traininfo.LimitNumber; model.PhotoID = traininfo.PhotoID; model.PublishTime = traininfo.PublishTime; model.UserID = traininfo.UserID; model.Host = traininfo.Host; model.DeleteMark = false; model.StatusCode = GetStatuCode(traininfo.StartTime, traininfo.EndTime, traininfo.ApplySTime, traininfo.ApplyETime); result = service.Insert(model); } else { var train = service.FindEntity(keyValue); train.TrainTitle = traininfo.TrainTitle; train.ApplyETime = traininfo.ApplyETime; train.ApplySTime = traininfo.ApplySTime; train.StartTime = traininfo.StartTime; train.EndTime = traininfo.EndTime; train.Content = traininfo.Content; train.PartNumber = traininfo.PartNumber; train.LimitNumber = traininfo.LimitNumber; train.PhotoID = traininfo.PhotoID; train.PublishTime = traininfo.PublishTime; train.UserID = traininfo.UserID; train.Host = traininfo.Host; train.Address = traininfo.Address; train.StatusCode = GetStatuCode(traininfo.StartTime, traininfo.EndTime, traininfo.ApplySTime, traininfo.ApplyETime); result = service.Update(train); } return(result); }
public async Task UpdateOne() { using var mocker = AutoMock.GetStrict(); await using var handler = mocker.Create <UpdateCountEventHandler>(); var stations = Enumerable.Range(100, 4).ToArray(); var maxCount = 10000; var state = TrainInfo.Create(stations, maxCount); var evt = new UpdateCountEvent { FromStationId = 100, ToStationId = 101 }; await handler.HandleEvent(state, evt, default); var leftCount = maxCount - 1; state.SeatCount.Count.Should().Be(6); state.GetSeatCount(100, 101).Should().Be(leftCount); state.GetSeatCount(100, 102).Should().Be(leftCount); state.GetSeatCount(100, 103).Should().Be(leftCount); state.GetSeatCount(101, 102).Should().Be(maxCount); state.GetSeatCount(101, 103).Should().Be(maxCount); state.GetSeatCount(102, 103).Should().Be(maxCount); }