public async Task <IActionResult> PutGive(long id, Give give) { if (id != give.Id) { return(BadRequest()); } _context.Entry(give).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GiveExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public void Static_Api_Multi() { var testModels = Give <TestModel> .Many(5); Assert.Equal(testModels.Count, 5); Assert.True(testModels.All(tm => tm != null && tm.CompanyField == null && tm.OrdersProp == null)); }
public override void GenerateAbstractQuests(int maxDepth) { this.Quests.questgiver = this.questgiver; Random r = new Random(); switch (r.Next(2)) { case 0: //Attack enemies this.sqName = "Attack enemies"; this.AddQuest(new GoTo(0, maxDepth)); Quest damage = new Damage(); damage.QuestText.Add("We need to hit them, where it hurts."); this.AddQuest(damage); break; case 1: //Steal stuff this.sqName = "Steal stuff"; this.AddQuest(new GoTo(0, maxDepth)); this.AddQuest(new Steal(1, maxDepth)); this.AddQuest(new GoTo(2, maxDepth)); Quest give = new Give(); give.QuestText.Add("We need to take , what belongs to us."); this.AddQuest(give); break; } }
public override void GenerateAbstractQuests(int maxDepth) { this.Quests.questgiver = this.questgiver; Random r = new Random(); switch (r.Next(2)) { case 0: //Kill pests this.sqName = "Kill pests"; this.AddQuest(new GoTo(0, maxDepth)); this.AddQuest(new Damage()); this.AddQuest(new GoTo(2, maxDepth)); Quest report = new Report(); report.QuestText.Add("We need to cull them before they overrun us."); this.AddQuest(report); break; case 1: //Obtain Luxuries this.sqName = "Obtain luxuries"; this.AddQuest(new Get(0, maxDepth)); this.AddQuest(new GoTo(1, maxDepth)); Quest give = new Give(); give.QuestText.Add("He will definitely appreciate it."); this.AddQuest(give); break; } }
public void Static_Api_Single() { var testModel = Give <TestModel> .Single(); Assert.NotNull(testModel); Assert.Null(testModel.CompanyField); Assert.Null(testModel.OrdersProp); }
public void Instance_Api_Multi() { var give = new Give(Enumerable.Empty <IValueGenerator>()); var testModels = give.Many <TestModel>(5); Assert.Equal(testModels.Count, 5); Assert.True(testModels.All(tm => tm != null && tm.CompanyField == null && tm.OrdersProp == null)); }
public void Static_Api_Single_Convert() { TestModel testModel = Give <TestModel> .ToMe(); Assert.NotNull(testModel); Assert.Null(testModel.CompanyField); Assert.Null(testModel.OrdersProp); }
public void Instance_Api_Single_Convert() { var give = new Give(); TestModel testModel = give.Me <TestModel>(); Assert.NotNull(testModel); Assert.Null(testModel.CompanyField); Assert.Null(testModel.OrdersProp); }
public ExpressionTests() { var orders = Give <Order> .ToMe(o => o.OrderDetails = Give <OrderDetail> .ToMe(od => od.Product = Give <Product> .ToMe(p => p.Supplier = Give <Company> .Single()) ).Now(5) ).Now(20); orders[3].Id = 5; _query = orders.AsQueryable(); }
public void Map_With_NonList() { var config = new MapConfiguration(); config.RegisterMap <Customer, CustomerDTO>(); var customers = Give <Customer> .Many(5); var dtos = config.Map <Customer, CustomerDTO>(customers); Assert.Equal(dtos.Count(), 5); }
public StaticTests() { Customers = Give <Customer> .ToMe(c => { var addresses = Give <Address> .ToMe(a => a.City = Give <City> .Single()) .Now(3); c.Addresses = addresses; c.MainAddress = addresses[0]; }) .Now(5); }
public override void GenerateAbstractQuests(int maxDepth) { this.Quests.questgiver = this.questgiver; Random r = new Random(); switch (r.Next(4)) { case 0: //Spy this.sqName = "Spy"; Quest q = new Spy(); q.QuestText.Add("We need to know as much as we can."); this.AddQuest(q); break; case 1: //Interview NPC this.sqName = "Interview NPC"; this.AddQuest(new GoTo(0, maxDepth)); this.AddQuest(new Listen()); this.AddQuest(new GoTo(2, maxDepth)); Quest report = new Report(); report.QuestText.Add("We need to get the information where it needs to be."); this.AddQuest(report); break; case 2: //Deliver item for study this.sqName = "Deliver Item for study"; Quest get = new Get(0, maxDepth); this.AddQuest(get); this.AddQuest(new GoTo(1, maxDepth)); Quest give = new Give(); give.Vars[0] = get.Vars[0]; give.QuestText.Add("They'll study the item and we will know more."); this.AddQuest(give); break; case 3: //Use item in the field this.sqName = "Use item in the field"; this.AddQuest(new Give()); this.AddQuest(new GoTo(1, maxDepth)); Quest use = new Use(); use.QuestText.Add(" observe it's behavior."); this.AddQuest(use); this.AddQuest(new GoTo(3, maxDepth)); this.AddQuest(new Give()); break; } }
public void Map_Orders_With_SkipMember_String() { var config = new MapConfiguration(); config.RegisterMap(typeof(Order), typeof(OrderDTO), b => { b.SkipMember("Price"); }); var order = Give <Order> .Single(); var orderDto = config.Map <OrderDTO>(order); Assert.NotEqual(order.Price, orderDto.Price); }
public void Map_Orders_With_SkipMember() { var config = new MapConfiguration(); config.RegisterMap <Order, OrderDTO>(b => { b.SkipMember(o => o.Price); }); var order = Give <Order> .Single(); var orderDto = config.Map <OrderDTO>(order); Assert.NotEqual(order.Price, orderDto.Price); }
public void Map_Orders_With_MapMember() { var config = new MapConfiguration(); config.RegisterMap <Order, OrderDTO>(b => { b.MapMember(o => o.Price, (o, mc) => o.Price * 3); }); var order = Give <Order> .Single(); var orderDto = config.Map <OrderDTO>(order); Assert.True(orderDto.Price.Equals(order.Price * 3)); }
public ExpressionTests() { var orders = Give <Order> .ToMe(o => o.Lines = Give <OrderLine> .ToMe(od => { od.OrderId = o.Id; od.Order = o; od.Product = Give <Product> .ToMe(p => p.Supplier = Give <Company> .Single()); }).Now(new Random().Next(3, 15)) ).Now(20); AvgId = orders.Average(o => o.Id); _query = orders.AsQueryable(); }
public void Map_Orders_With_MapMember_String() { var config = new MapConfiguration(); config.RegisterMap <OrderDTO, Order>(); config.RegisterMap(typeof(OrderDetailDTO), typeof(OrderDetail), b => { b.MapMember("OrderId", "Order.Id"); }); var orderDetailDto = Give <OrderDetailDTO> .ToMe().With(od => od.Order = Give <OrderDTO> .Single()).Now(); var orderDetail = config.Map <OrderDetail>(orderDetailDto); Assert.True(orderDetail.OrderId.Equals(orderDetailDto.Order.Id)); }
public void Map_Dictionary_With_Class_Key() { var config = new MapConfiguration(); config.RegisterMap <Customer, CustomerDTO>(); var customer = Give <Customer> .Single(); var dict = new Dictionary <Customer, int> { { customer, customer.Id } }; var dtoDict = config.Map <Customer, int, CustomerDTO, int>(dict); Assert.Equal(customer.Id, dtoDict.First().Key.Id); }
public QueryableTests() { var random = new Random(); var products = Give <Product> .ToMe(p => p.Supplier = Give <Company> .ToMe(s => s.Addresses = Give <Address> .Many(2)).Now()) .Now(15); _orders = Give <Order> .ToMe(o => { o.OrderDetails = Give <OrderDetail> .ToMe(od => od.Product = products[random.Next(15)]) .Now(3); }) .Now(10); }
public void Map_Orders_PreserveReferences_2() { var config = new MapConfiguration(DynamicMapping.MapAndCache); var order = Give <Order> .Single(); var orderDetail = Give <OrderDetail> .Single(); order.OrderDetails = new List <OrderDetail> { orderDetail }; orderDetail.Order = order; var orderDto = config.Map <OrderDTO>(order, true); Assert.Equal(orderDto, orderDto.OrderDetails.First().Order); }
public void Map_To_Collection_Property() { var entity = Give <ForTest5> .ToMe(c => { c.Cities = new Collection <City>(Give <City> .Many(10)); }) .Now(); var config = new MapConfiguration(); config.RegisterMap <ForTest5, ForTest5DTO>((e, mc) => new ForTest5DTO { Cities = mc.MapToCollection <City, CityDTO>(e.Cities) }); config.RegisterMap <City, CityDTO>(); var dto = config.Map <ForTest5, ForTest5DTO>(entity); Assert.True(dto.Cities[2].Name == entity.Cities[2].Name); }
public override void GenerateAbstractQuests(int maxDepth) { this.Quests.questgiver = this.questgiver; Random r = new Random(); switch (r.Next(4)) { case 0: //Assemble this.sqName = "Assemble"; Quest q = new Repair(); this.AddQuest(q); break; case 1: //Deliver supplies this.sqName = "Deliver supplies"; this.AddQuest(new Get(0, maxDepth)); this.AddQuest(new GoTo(1, maxDepth)); Quest report = new Give(); report.QuestText.Add(""); this.AddQuest(report); break; case 2: //Steal supplies this.sqName = "Steal supplies"; Quest steal = new Steal(0, maxDepth); this.AddQuest(steal); Quest give = new Give(); give.QuestText.Add("We need the supplies at all costs."); this.AddQuest(give); break; case 3: //Trade supplies this.sqName = "Trade supplies"; this.AddQuest(new GoTo(0, maxDepth)); Quest use = new Exchange(); use.QuestText.Add("Good luck with your trade."); this.AddQuest(use); break; } }
public void Map_Collection_Property() { var entities = Give <ForTest5> .ToMe(c => { c.Cities = new Collection <City>(Give <City> .Many(10)); }) .Now(5); entities[4].Cities = null; var config = new MapConfiguration(); config.RegisterMap <ForTest5, ForTest5DTO>(); config.RegisterMap <City, CityDTO>(); var dtos = config.Map <ForTest5, ForTest5DTO>(entities).ToList(); Assert.True(dtos[3].Cities[2].Name == entities[3].Cities[2].Name); Assert.Null(dtos[4].Cities); }
public ComplexDataTests() { var random = new Random(); var products = Give <Product> .ToMe(p => p.Supplier = Give <Company> .Single()) .Now(15); _orders = Give <Order> .ToMe(o => { o.OrderDetails = Give <OrderDetail> .ToMe(od => od.Product = products[random.Next(15)]) .Now(3); }) .Now(10); _orders[5].OrderDetails[1].Product = products[9]; _orders[7].OrderDetails[1].Product = products[9]; }
public void Map_HashSet_Property() { var entities = Give <ForTest6> .ToMe(c => { c.Cities = new HashSet <City>(Give <City> .Many(10)); }) .Now(5); entities[4].Cities = null; var config = new MapConfiguration(); config.RegisterMap <ForTest6, ForTest6DTO>(); config.RegisterMap <City, CityDTO>(); var dtos = config.Map <ForTest6, ForTest6DTO>(entities).ToList(); Assert.True(dtos[3].Cities.First().Name == entities[3].Cities.First().Name); Assert.Null(dtos[4].Cities); }
static Program() { var rnd = new Random(); _customers = Give <Customer> .ToMe() .With(c => { c.Addresses = Give <Address> .ToMe() .With(a => a.City = Give <City> .Single()) .Now(rnd.Next(3) + 1); c.Orders = Give <Order> .ToMe() .With(o => o.OrderDetails = Give <OrderDetail> .Many(rnd.Next(5) + 1)) .Now(rnd.Next(10) + 1); }) .Now(1000); Mapper.RegisterMap <Customer, CustomerDTO>(); Mapper.RegisterMap <Address, AddressDTO>(); Mapper.RegisterMap <City, CityDTO>(); Mapper.RegisterMap <Order, OrderDTO>(); Mapper.RegisterMap <OrderDetail, OrderDetailDTO>(); global::AutoMapper.Mapper.Initialize(cfg => { cfg.CreateMap <Customer, CustomerDTO>(); cfg.CreateMap <Address, AddressDTO>(); cfg.CreateMap <City, CityDTO>(); cfg.CreateMap <Order, OrderDTO>(); cfg.CreateMap <OrderDetail, OrderDetailDTO>(); }); #if NET global::ExpressMapper.Mapper.Register <Customer, CustomerDTO>(); global::ExpressMapper.Mapper.Register <Address, AddressDTO>(); global::ExpressMapper.Mapper.Register <City, CityDTO>(); global::ExpressMapper.Mapper.Register <Order, OrderDTO>(); global::ExpressMapper.Mapper.Register <OrderDetail, OrderDetailDTO>(); Nelibur.ObjectMapper.TinyMapper.Bind <Customer, CustomerDTO>(); Nelibur.ObjectMapper.TinyMapper.Bind <Address, AddressDTO>(); Nelibur.ObjectMapper.TinyMapper.Bind <City, CityDTO>(); Nelibur.ObjectMapper.TinyMapper.Bind <Order, OrderDTO>(); Nelibur.ObjectMapper.TinyMapper.Bind <OrderDetail, OrderDetailDTO>(); #endif }
public void Solve() { var input = ReadAll(); var instructions = input.Split("\r\n".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); var search = UnsignedInteger("val1") + NonDigit.Rep(0, isLazy: true) + "output".Named("out1").Optional() + " " + UnsignedInteger("val2") + (NonDigit.Rep(0, isLazy: true) + "output".Named("out2").Optional() + " " + UnsignedInteger("val3")).Optional(); var regex = new Regex(search); var inits = new List <Init>(); var gives = new Dictionary <int, Give>(); var maxBot = 0; foreach (var instruction in instructions) { var match = regex.Match(instruction); var val1 = int.Parse(match.Groups["val1"].Value); var val2 = int.Parse(match.Groups["val2"].Value); if (match.Groups["val3"].Success) { var val3 = int.Parse(match.Groups["val3"].Value); gives[val1] = new Give(val2, match.Groups["out1"].Success, val3, match.Groups["out2"].Success); maxBot = Math.Max(maxBot, val1); maxBot = Math.Max(maxBot, val2); maxBot = Math.Max(maxBot, val3); } else { inits.Add(new Init(val1, val2)); maxBot = Math.Max(maxBot, val2); } } var firstValues = Enumerable.Repeat(-1, maxBot + 1).ToArray(); var outs = new int[maxBot + 1]; inits.ForEach(init => GiveTo(init.Bot, init.Value, firstValues, gives, outs)); WriteLine(_problem1Bot); WriteLine(outs[0] * outs[1] * outs[2]); }
public AdventureCommandRegistry(IReadonlyAdventureGame game) { var lookCommand = new Look(game, "look", "l"); var helpCommand = new Help(game, "help"); var moveCommand = new Move(game, "move", "go", "walk", "run", "climb", "crawl", "head"); var takeCommand = new Take(game, "take", "get", "grab"); var dropCommand = new Drop(game, "drop", "discard"); var magicWord1 = new Xyzzy(game, "xyzzy"); var magicWord2 = new Plugh(game, "plugh"); var inventoryCommand = new Carrying(game, "inventory", "inv"); var interactCommand = new Interact(game, "use"); // Do not add aliases for this command var yes = new Yes(game, "yes", "y"); var no = new No(game, "no", "n"); var say = new Say(game, "say"); var back = new Back(game, "back", "retreat"); var give = new Give(game, "give"); var attack = new Attack(game, "attack", "assault", "kill", "murder", "slay"); // ToDo: Remove this as its for TESTING ONLY var teleport = new Teleport(game, "teleport"); RegisteredCommands = new List <IAdventureCommand> { lookCommand, helpCommand, moveCommand, takeCommand, dropCommand, magicWord1, magicWord2, inventoryCommand, interactCommand, yes, no, say, back, teleport, give, attack, }; }
public override void GenerateAbstractQuests(int maxDepth) { this.Quests.questgiver = this.questgiver; Random r = new Random(); switch (r.Next(3)) { case 0: //Gather materials this.sqName = "Obtain rare item"; this.AddQuest(new Get(0, maxDepth)); this.AddQuest(new GoTo(1, maxDepth)); Quest q = new Give(); q.QuestText.Add(""); this.AddQuest(q); break; case 1: //Ability this.sqName = "Kill enemies"; this.AddQuest(new GoTo(0, maxDepth)); this.AddQuest(new Kill(1, maxDepth)); this.AddQuest(new GoTo(2, maxDepth)); Quest report = new Report(); report.QuestText.Add("This will show them we're not to be triffled with."); this.AddQuest(report); break; case 2: //Visit a danagerous place this.sqName = "Visit a dangerous place"; this.AddQuest(new GoTo(0, maxDepth)); this.AddQuest(new GoTo(1, maxDepth)); Quest report1 = new Report(); report1.QuestText.Add("The place is dangerous, but what you find might bring us respect we deserve."); this.AddQuest(report1); break; } }
public void Map_With_Preserve_References() { var config = new MapConfiguration(); config.RegisterMap <OrderDetail, OrderDetailDTO>(); config.RegisterMap <Product, ProductDTO>(); var orderDetail1 = Give <OrderDetail> .Single(); var orderDetail2 = Give <OrderDetail> .Single(); var product = Give <Product> .Single(); orderDetail1.Product = product; orderDetail2.Product = product; var orderDetails = new List <OrderDetail> { orderDetail1, orderDetail2 }; var dtos = config.Map <OrderDetail, OrderDetailDTO>(orderDetails, true).ToList(); Assert.Equal(dtos[0].Product, dtos[1].Product); }