public void AddPets_WithVaildData_ReturnsListOfPets() { int PetId = new Random().Next(90001, 190000); var petService = new PetService(); Pets petObject = new Pets() { Id = PetId, Name = "George", Age = 10, Place = "Hyd", IsAvailable = 1, OwnerId = "a" }; petService.AddPet(petObject); Assert.Pass(); }
public ISellableItem PurchaseItem(ShopItem item) { var shopItem = item.Item; if (shopItem is Creature) { // create a pet. var option = ShopItemsHelper.GetPetName(item); if (option == null) { return(null); } var newPet = Pet.ConcreteStarterPet(shopItem as Creature, option.Value.ToString()); PetService.AddPet(Player, newPet); return(newPet); } if (shopItem is CreatureAttack) { var option = ShopItemsHelper.GetAttackPetId(item); if (option == null) { return(null); } try { var petId = Convert.ToInt32(option.Value); var pet = PetService.GetPet(petId); pet.Attacks.Add(shopItem as CreatureAttack); } catch (Exception e) { return(null); } } else if (shopItem is Food) { Player.Food.Add(shopItem as Food); } return(shopItem); }
/// <summary> /// Sets up HTTP methods mappings. /// </summary> /// <param name="service">Service handling requests</param> public PetModule(PetService service) : base("/v2") { Post["/pet"] = parameters => { var body = this.Bind <Pet>(); Preconditions.IsNotNull(body, "Required parameter: 'body' is missing at 'AddPet'"); service.AddPet(Context, body); return(new Response { ContentType = "" }); }; Delete["/pet/{petId}"] = parameters => { var petId = Parameters.ValueOf <long?>(parameters, Context.Request, "petId", ParameterType.Path); var apiKey = Parameters.ValueOf <string>(parameters, Context.Request, "apiKey", ParameterType.Header); Preconditions.IsNotNull(petId, "Required parameter: 'petId' is missing at 'DeletePet'"); service.DeletePet(Context, petId, apiKey); return(new Response { ContentType = "" }); }; Get["/pet/findByStatus"] = parameters => { var status = Parameters.ValueOf <FindPetsByStatusStatusEnum?>(parameters, Context.Request, "status", ParameterType.Query); Preconditions.IsNotNull(status, "Required parameter: 'status' is missing at 'FindPetsByStatus'"); return(service.FindPetsByStatus(Context, status).ToArray()); }; Get["/pet/findByTags"] = parameters => { var tags = Parameters.ValueOf <List <string> >(parameters, Context.Request, "tags", ParameterType.Query); Preconditions.IsNotNull(tags, "Required parameter: 'tags' is missing at 'FindPetsByTags'"); return(service.FindPetsByTags(Context, tags).ToArray()); }; Get["/pet/{petId}"] = parameters => { var petId = Parameters.ValueOf <long?>(parameters, Context.Request, "petId", ParameterType.Path); Preconditions.IsNotNull(petId, "Required parameter: 'petId' is missing at 'GetPetById'"); return(service.GetPetById(Context, petId)); }; Put["/pet"] = parameters => { var body = this.Bind <Pet>(); Preconditions.IsNotNull(body, "Required parameter: 'body' is missing at 'UpdatePet'"); service.UpdatePet(Context, body); return(new Response { ContentType = "" }); }; Post["/pet/{petId}"] = parameters => { var petId = Parameters.ValueOf <long?>(parameters, Context.Request, "petId", ParameterType.Path); var name = Parameters.ValueOf <string>(parameters, Context.Request, "name", ParameterType.Undefined); var status = Parameters.ValueOf <string>(parameters, Context.Request, "status", ParameterType.Undefined); Preconditions.IsNotNull(petId, "Required parameter: 'petId' is missing at 'UpdatePetWithForm'"); service.UpdatePetWithForm(Context, petId, name, status); return(new Response { ContentType = "" }); }; Post["/pet/{petId}/uploadImage"] = parameters => { var petId = Parameters.ValueOf <long?>(parameters, Context.Request, "petId", ParameterType.Path); var additionalMetadata = Parameters.ValueOf <string>(parameters, Context.Request, "additionalMetadata", ParameterType.Undefined); var file = Parameters.ValueOf <System.IO.Stream>(parameters, Context.Request, "file", ParameterType.Undefined); Preconditions.IsNotNull(petId, "Required parameter: 'petId' is missing at 'UploadFile'"); return(service.UploadFile(Context, petId, additionalMetadata, file)); }; }
/// <summary> /// Sets up HTTP methods mappings. /// </summary> /// <param name="service">Service handling requests</param> public PetModule(PetService service) : base("/v2") { Post["/pet"] = parameters => { var body = this.Bind<Pet>(); service.AddPet(Context, body); return new Response { ContentType = "application/json"}; }; Delete["/pet/{petId}"] = parameters => { var petId = Parameters.ValueOf<long?>(parameters, Context.Request, "petId", ParameterType.Path); var apiKey = Parameters.ValueOf<string>(parameters, Context.Request, "apiKey", ParameterType.Header); Preconditions.IsNotNull(petId, "Required parameter: 'petId' is missing at 'DeletePet'"); service.DeletePet(Context, petId, apiKey); return new Response { ContentType = "application/json"}; }; Get["/pet/findByStatus"] = parameters => { var status = Parameters.ValueOf<List<string>>(parameters, Context.Request, "status", ParameterType.Query); return service.FindPetsByStatus(Context, status); }; Get["/pet/findByTags"] = parameters => { var tags = Parameters.ValueOf<List<string>>(parameters, Context.Request, "tags", ParameterType.Query); return service.FindPetsByTags(Context, tags); }; Get["/pet/{petId}"] = parameters => { var petId = Parameters.ValueOf<long?>(parameters, Context.Request, "petId", ParameterType.Path); Preconditions.IsNotNull(petId, "Required parameter: 'petId' is missing at 'GetPetById'"); return service.GetPetById(Context, petId); }; Put["/pet"] = parameters => { var body = this.Bind<Pet>(); service.UpdatePet(Context, body); return new Response { ContentType = "application/json"}; }; Post["/pet/{petId}"] = parameters => { var petId = Parameters.ValueOf<string>(parameters, Context.Request, "petId", ParameterType.Path); var name = Parameters.ValueOf<string>(parameters, Context.Request, "name", ParameterType.Undefined); var status = Parameters.ValueOf<string>(parameters, Context.Request, "status", ParameterType.Undefined); Preconditions.IsNotNull(petId, "Required parameter: 'petId' is missing at 'UpdatePetWithForm'"); service.UpdatePetWithForm(Context, petId, name, status); return new Response { ContentType = "application/json"}; }; Post["/pet/{petId}/uploadImage"] = parameters => { var petId = Parameters.ValueOf<long?>(parameters, Context.Request, "petId", ParameterType.Path); var additionalMetadata = Parameters.ValueOf<string>(parameters, Context.Request, "additionalMetadata", ParameterType.Undefined); var file = Parameters.ValueOf<System.IO.Stream>(parameters, Context.Request, "file", ParameterType.Undefined); Preconditions.IsNotNull(petId, "Required parameter: 'petId' is missing at 'UploadFile'"); service.UploadFile(Context, petId, additionalMetadata, file); return new Response { ContentType = "application/json"}; }; }