private void CreateTestData(NYCLandmarkContext dbContext) { var i = 0; var boroughs = EnumHelper.EnumToList <Borough>().Select(e => e.GetDescription()); var boroughCodes = EnumHelper.EnumToList <Borough>().Select(e => e.GetAttribute <BoroughId>().Value); var objectTypes = EnumHelper.EnumToList <ObjectType>().Select(e => e.GetDescription()); GenFu.GenFu.Configure <LPCReport>() .Fill(l => l.Id, () => ++ i) .Fill(l => l.LPNumber, () => string.Format("LP-{0,5:D5}", i)) .Fill(l => l.LPCId, () => string.Format("{0,5:D5}", i)) .Fill(l => l.Borough, () => BaseValueGenerator.GetRandomValue(boroughs)) .Fill(l => l.ObjectType, () => BaseValueGenerator.GetRandomValue(objectTypes)); var lpcReports = GenFu.GenFu.ListOf <LPCReport>(20); dbContext.LPCReports.AddRange(lpcReports); var j = 0; GenFu.GenFu.Configure <Landmark>() .Fill(m => m.Id, () => ++ j) .Fill(l => l.LM_TYPE, () => BaseValueGenerator.GetRandomValue(objectTypes)) .Fill(l => l.BoroughID, () => BaseValueGenerator.GetRandomValue(boroughCodes)) .Fill(m => m.LP_NUMBER, () => string.Format("LP-{0,5:D5}", j)); var landmarks = GenFu.GenFu.ListOf <Landmark>(20); dbContext.Landmarks.AddRange(landmarks); dbContext.SaveChanges(); }
public async Task ScheduleAsync_SkipSchedulesThatAlreadyExists() { // Arrange var name = BaseValueGenerator.Word(); var queueName = Default.Queue; var cron = Cron.Weekly(); var payload = Guid.NewGuid().ToByteArray(); var command = new BasicCommand(); var cancellationToken = CancellationToken.None; var existingItem = new ScheduleItem { CronExpression = cron.Expression, Name = name, Payload = payload, Queue = queueName }; _payloadSerializer.SerializeAsync(command, cancellationToken).Returns(Task.FromResult(payload)); _payloadProtector.ProtectAsync(payload, cancellationToken).Returns(Task.FromResult(payload)); _scheduleProviderFactory.CreateAsync(queueName, cancellationToken).Returns(Task.FromResult(_scheduleProvider)); _scheduleProvider.LoadByNameAsync(name, cancellationToken).Returns(Task.FromResult(existingItem)); // Act await _sut.ScheduleAsync(name, command, cron, cancellationToken); // Assert await _scheduleProvider.DidNotReceiveWithAnyArgs().CreateAsync(default(ScheduleItem), cancellationToken); }
public async Task ScheduleAsync_DeleteSchedulesThatExistButHaveDifferentCronExpressions() { // Arrange var name = BaseValueGenerator.Word(); var queueName = Default.Queue; var cron = Cron.Daily(); var payload = Guid.NewGuid().ToByteArray(); var command = new BasicCommand(); var cancellationToken = CancellationToken.None; var existingItem = new ScheduleItem { Id = Guid.NewGuid(), CronExpression = Cron.Weekly().Expression, Name = name, Payload = Guid.NewGuid().ToByteArray(), Queue = queueName }; _payloadSerializer.SerializeAsync(command, cancellationToken).Returns(Task.FromResult(payload)); _scheduleProviderFactory.CreateAsync(queueName, cancellationToken).Returns(Task.FromResult(_scheduleProvider)); _scheduleProvider.LoadByNameAsync(name, cancellationToken).Returns(Task.FromResult(existingItem)); // Act await _sut.ScheduleAsync(name, command, Cron.Daily(), cancellationToken); // Assert await _scheduleProvider.Received(1).DeleteAsync(existingItem.Id, cancellationToken); await _scheduleProvider.Received(1).CreateAsync(Arg.Is <ScheduleItem>(x => x.Queue == queueName && x.CronExpression == cron.Expression), cancellationToken); }
public void GetRandomValueFromArray() { string[] possibleValues = new[] { "A", "B", "C", "D", "E" }; for (int i = 0; i < 500; i++) { string randomValue = BaseValueGenerator.GetRandomValue(possibleValues); Assert.IsNotNullOrEmpty(randomValue); CollectionAssert.Contains(possibleValues, randomValue); } }
public void GetRandomValueFromEnumerable() { IEnumerable <string> possibleValues = (new [] { "1A", "2A", "3A", "4A", "5A" }).Select(s => s); for (int i = 0; i < 500; i++) { string randomValue = BaseValueGenerator.GetRandomValue(possibleValues); Assert.IsNotNullOrEmpty(randomValue); CollectionAssert.Contains(possibleValues, randomValue); } }
public void GetRandomValueFromArray() { string[] possibleValues = new[] { "A", "B", "C", "D", "E" }; for (int i = 0; i < 500; i++) { string randomValue = BaseValueGenerator.GetRandomValue(possibleValues); Assert.NotNull(randomValue); Assert.NotEmpty(randomValue); Assert.True(possibleValues.Contains(randomValue)); } }
public static List <LandmarkModel> GetLandmarkModelList(int count) { var boroughCodes = EnumHelper.EnumToList <Borough>().Select(e => e.GetAttribute <BoroughIdAttribute>().Value); GenFu.GenFu.Configure <LandmarkModel>() .Fill(p => p.Name) .Fill(p => p.BoroughId, () => BaseValueGenerator.GetRandomValue(boroughCodes)) .Fill(p => p.Street).AsAddress(); return(GenFu.GenFu.ListOf <LandmarkModel>(count)); }
public static List <Landmark> GetLandmarkList(int count) { var boroughCodes = EnumHelper.EnumToList <Borough>().Select(e => e.GetAttribute <BoroughIdAttribute>().Value); GenFu.GenFu.Configure <Landmark>() .Fill(p => p.LM_NAME) .Fill(p => p.BoroughID, () => BaseValueGenerator.GetRandomValue(boroughCodes)) .Fill(p => p.DESIG_ADDR).AsAddress() .Fill(p => p.PLUTO_ADDR).AsAddress(); return(GenFu.GenFu.ListOf <Landmark>(count)); }
public void GetRandomValueFromList() { List <string> possibleValues = new List <string> { "1", "2", "3", "4", "5" }; for (int i = 0; i < 500; i++) { string randomValue = BaseValueGenerator.GetRandomValue(possibleValues); Assert.IsNotNullOrEmpty(randomValue); CollectionAssert.Contains(possibleValues, randomValue); } }
public void GetRandomValueFromList() { List <string> possibleValues = new List <string> { "1", "2", "3", "4", "5" }; for (int i = 0; i < 500; i++) { string randomValue = BaseValueGenerator.GetRandomValue(possibleValues); Assert.NotNull(randomValue); Assert.NotEmpty(randomValue); Assert.True(possibleValues.Contains(randomValue)); } }
public async Task PublishAsync_WithDelayAndQueueName() { // Arrange var queueName = BaseValueGenerator.Word(); var command = new BasicCommand(); var delay = GenFu.GenFu.Random.Next(); var cancellationToken = CancellationToken.None; _payloadSerializer.SerializeAsync(command, cancellationToken).Returns(Task.FromResult <byte[]>(null)); _workProviderFactory.CreateAsync(queueName, cancellationToken).Returns(Task.FromResult(_workProvider)); // Act await _sut.PublishAsync(command, queueName, delay, cancellationToken); // Assert await _workProvider.Received(1).SendAsync(Arg.Is <WorkItem>(x => x.Queue == queueName), delay, cancellationToken); }
public async Task ScheduleAsync_WithQueueNameAttribute() { // Arrange var name = BaseValueGenerator.Word(); var queueName = "custom-queue-name"; var cron = Cron.Weekly(); var command = new BasicWithAttributeCommand(); var cancellationToken = CancellationToken.None; _payloadSerializer.SerializeAsync(command, cancellationToken).Returns(Task.FromResult <byte[]>(null)); _scheduleProviderFactory.CreateAsync(queueName, cancellationToken).Returns(Task.FromResult(_scheduleProvider)); // Act await _sut.ScheduleAsync(name, command, cron, cancellationToken); // Assert await _scheduleProvider.Received(1).CreateAsync(Arg.Is <ScheduleItem>(x => x.Queue == queueName && x.CronExpression == cron.Expression), cancellationToken); }
public static List <LpcReportModel> GetLpcReportModelList(int count) { var boroughs = EnumHelper.EnumToList <Borough>().Select(e => e.GetDescription()); var objectTypes = EnumHelper.EnumToList <ObjectType>().Select(e => e.GetDescription()); var i = 0; GenFu.GenFu.Configure <LpcReportModel>() .Fill(l => l.Id, () => ++ i) .Fill(l => l.LPNumber, () => $"LP-{i,5:D5}") .Fill(l => l.LPCId, () => $"{i,5:D5}") .Fill(p => p.Name) .Fill(l => l.Borough, () => BaseValueGenerator.GetRandomValue(boroughs)) .Fill(l => l.ObjectType, () => BaseValueGenerator.GetRandomValue(objectTypes)) .Fill(p => p.PhotoStatus, true) .Fill(p => p.Street).AsAddress(); return(GenFu.GenFu.ListOf <LpcReportModel>(count)); }
private void CreateTestData(NycLandmarkContext dbContext) { var boroughs = EnumHelper.EnumToList <Borough>().Select(e => e.GetDescription()); var objectTypes = EnumHelper.EnumToList <ObjectType>().Select(e => e.GetDescription()); var i = 0; GenFu.GenFu.Configure <LpcReport>() .Fill(l => l.Id, () => ++ i) .Fill(l => l.LPNumber, () => $"LP-{i,5:D5}") .Fill(l => l.LPCId, () => $"{i,5:D5}") .Fill(l => l.Borough, () => BaseValueGenerator.GetRandomValue(boroughs)) .Fill(l => l.ObjectType, () => BaseValueGenerator.GetRandomValue(objectTypes)) .Fill(l => l.Landmarks); _lpcReports = GenFu.GenFu.ListOf <LpcReport>(20); dbContext.LPCReports.AddRange(_lpcReports); dbContext.SaveChanges(); }