public static IEnumerable <object[]> CreateVehicleData()
        {
            yield return(new object[] { EStatusCode.InvalidData, new CreateVehicle {
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new CreateVehicle {
                                            Id = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new CreateVehicle {
                                            Id = RandomId.NewId(), FuelId = EFuel.Flex
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new CreateVehicle {
                                            Id = RandomId.NewId(), FuelId = EFuel.Flex, ColorId = EColor.Black
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new CreateVehicle {
                                            Id = RandomId.NewId(), FuelId = EFuel.Flex, ColorId = EColor.Black, Year = 2010
                                        } });

            yield return(new object[] { EStatusCode.NotFound, new CreateVehicle {
                                            Id = RandomId.NewId(), FuelId = EFuel.Flex, ColorId = EColor.Black, Year = 2010, ModelId = RandomId.NewId()
                                        }, false });

            yield return(new object[] { EStatusCode.Success, new CreateVehicle {
                                            Id = RandomId.NewId(), FuelId = EFuel.Flex, ColorId = EColor.Black, Year = 2010, ModelId = RandomId.NewId()
                                        }, true });
        }
Example #2
0
        public async void CreateAlbumTest()
        {
            var genreId  = RandomId.NewId();
            var objGenre = new Genre(genreId, "genre test");

            objGenre.AddCashbackConfig(new Domain.Models.Cashback(null, genreId, System.DayOfWeek.Monday, 10));
            await DbContext.Genres.AddAsync(objGenre);

            await DbContext.SaveChangesAsync();

            var id  = RandomId.NewId();
            var cmd = new CreateAlbumCommand()
            {
                Id        = id,
                Name      = "Test Genre 1",
                GenreId   = genreId,
                SpotifyId = null
            };

            var result = await CommandsHandler.Handle(cmd);

            var obj = await DbContext.Albums.Where(w => w.Id == id).FirstOrDefaultAsync();

            Assert.NotNull(result);
            Assert.NotNull(obj);
            Assert.Equal(ErrorCode.None, result.ErrorCode);
            Assert.Equal(id, obj.Id);
            Assert.True(result.Rows > 0);
        }
Example #3
0
        public static IEnumerable <object[]> CreateModelData()
        {
            yield return(new object[] { EStatusCode.InvalidData, new CreateModel {
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new CreateModel {
                                            Id = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new CreateModel {
                                            Id = RandomId.NewId(), Name = RandomId.NewId(250)
                                        } });

            yield return(new object[] { EStatusCode.Conflict, new CreateModel {
                                            Id = RandomId.NewId(), Name = RandomId.NewId(200), BrandId = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.NotFound, new CreateModel {
                                            Id = RandomId.NewId(), Name = RandomId.NewId(200), BrandId = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.Success, new CreateModel {
                                            Id = RandomId.NewId(), Name = RandomId.NewId(200), BrandId = RandomId.NewId()
                                        } });
        }
Example #4
0
 public Sale(
     string id,
     string customerName
     ) : this()
 {
     this.Id           = string.IsNullOrWhiteSpace(id) ? RandomId.NewId() : id;
     this.CustomerName = customerName;
 }
Example #5
0
 public Brand(
     string id,
     string name
     ) : this()
 {
     this.Id = string.IsNullOrWhiteSpace(id) ? RandomId.NewId() : id;
     this.SetData(name: name);
 }
Example #6
0
 public Album(string id, string spotifyId, string name, string genreId)
 {
     this.Id        = string.IsNullOrWhiteSpace(id) ? RandomId.NewId() : id;
     this.SpotifyId = spotifyId;
     this.Name      = name;
     this.Genre     = new Genre(genreId);
     this.Value     = Convert.ToDecimal(new Random().Next(1, 50));
 }
        public static IEnumerable <object[]> ListVehiclesData()
        {
            yield return(new object[] { EStatusCode.Success, new ListVehicles {
                                        } });

            yield return(new object[] { EStatusCode.Success, new ListVehicles {
                                            Year = 2010, BrandId = RandomId.NewId(), ModelId = RandomId.NewId(), FuelId = EFuel.Alcohol, ColorId = EColor.Black
                                        } });
        }
Example #8
0
 public void AddItem(SaleItem item)
 {
     if (item.Id == null)
     {
         item.Id = RandomId.NewId();
     }
     item.Sale = this;
     _items.Add(item);
 }
        public static IEnumerable <object[]> ListModelsSelectData()
        {
            yield return(new object[] { EStatusCode.Success, new ListModelsSelect {
                                        } });

            yield return(new object[] { EStatusCode.Success, new ListModelsSelect {
                                            BrandId = RandomId.NewId()
                                        } });
        }
Example #10
0
 public void AddCashbackConfig(Cashback cashback)
 {
     if (cashback.Id == null)
     {
         cashback.Id = RandomId.NewId();
     }
     cashback.Genre = this;
     this.Cashbacks.Add(cashback);
 }
Example #11
0
        public static IEnumerable <object[]> GetBrandData()
        {
            yield return(new object[] { EStatusCode.NotFound, new GetBrand {
                                            Id = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.Success, new GetBrand {
                                            Id = RandomId.NewId()
                                        } });
        }
        public static IEnumerable <object[]> GetVehiclePhotoData()
        {
            yield return(new object[] { EStatusCode.NotFound, new GetVehiclePhoto {
                                            Id = RandomId.NewId()
                                        }, false });

            yield return(new object[] { EStatusCode.Success, new GetVehiclePhoto {
                                            Id = RandomId.NewId()
                                        }, true });
        }
Example #13
0
 public Cashback(
     string id,
     string genreId,
     DayOfWeek dayOfWeek,
     decimal percent
     )
 {
     this.Id        = string.IsNullOrWhiteSpace(id) ? RandomId.NewId() : id;
     this.Genre     = new Genre(genreId);
     this.DayOfWeek = dayOfWeek;
     this.Percent   = percent;
 }
Example #14
0
 public Contact(
     string id,
     string name,
     string phone
     ) : this()
 {
     this.Id = string.IsNullOrWhiteSpace(id) ? RandomId.NewId() : id;
     this.SetData(
         name: name,
         phone: phone
         );
 }
Example #15
0
        public BuilderFactory <Brand> NewBrand(
            string id   = null,
            string name = null
            )
        {
            var brand = new Brand(
                id: id,
                name: name ?? RandomId.NewId(150)
                );

            return(new BuilderFactory <Brand>(brand, DbContext));
        }
Example #16
0
        public BuilderFactory <Contact> NewContact(
            string id    = null,
            string phone = null
            )
        {
            var contact = new Contact(
                id: RandomId.NewId(),
                name: RandomId.NewId(150),
                phone: phone ?? RandomId.NewId(15)
                );

            return(new BuilderFactory <Contact>(contact, DbContext));
        }
Example #17
0
        public static IEnumerable <object[]> DeleteVehicleData()
        {
            yield return(new object[] { EStatusCode.InvalidData, new DeleteVehicle {
                                        } });

            yield return(new object[] { EStatusCode.NotFound, new DeleteVehicle {
                                            Id = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.Success, new DeleteVehicle {
                                            Id = RandomId.NewId()
                                        } });
        }
Example #18
0
 public User(
     string id,
     string name,
     string login,
     string password
     ) : this()
 {
     this.Id       = string.IsNullOrWhiteSpace(id) ? RandomId.NewId() : id;
     this.Password = MD5Crypto.Encode(VehicleStartup.Secret + password);
     this.SetData(
         name: name,
         login: login
         );
 }
Example #19
0
        public BuilderFactory <User> NewUser(
            string login    = null,
            string password = null
            )
        {
            var user = new User(
                id: RandomId.NewId(),
                name: RandomId.NewId(150),
                login: login ?? RandomId.NewId(50),
                password: password ?? RandomId.NewId(50)
                );

            return(new BuilderFactory <User>(user, DbContext));
        }
Example #20
0
 public Model(
     string id,
     string name,
     string brandId,
     Brand brand = null
     ) : this()
 {
     this.Id = string.IsNullOrWhiteSpace(id) ? RandomId.NewId() : id;
     this.SetData(
         name: name,
         brandId: brandId,
         brand: brand
         );
 }
Example #21
0
        public BuilderFactory <Model> NewModel(
            string id      = null,
            string name    = null,
            string brandId = null
            )
        {
            var brand = NewBrand(id: brandId).Get();
            var model = new Model(
                id: id,
                name: name ?? RandomId.NewId(150),
                brandId: brand.Id,
                brand: brand
                );

            return(new BuilderFactory <Model>(model, DbContext));
        }
Example #22
0
 public Announcement(
     string id,
     decimal pricePurchase,
     decimal priceSale,
     DateTime?dateSale,
     string vehicleId,
     Vehicles.Entities.Vehicle vehicle = null
     ) : this()
 {
     this.Id = string.IsNullOrWhiteSpace(id) ? RandomId.NewId() : id;
     this.SetData(
         pricePurchase: pricePurchase,
         priceSale: priceSale,
         dateSale: dateSale,
         vehicleId: vehicleId,
         vehicle: vehicle
         );
 }
Example #23
0
 public Reservation(
     string id,
     string contactId,
     string announcementId,
     DateTime?dateSale         = null,
     Contact contact           = null,
     Announcement announcement = null
     ) : this()
 {
     this.Id        = string.IsNullOrWhiteSpace(id) ? RandomId.NewId() : id;
     this.ContactId = contactId;
     this.SetData(
         dateSale: dateSale,
         announcementId: announcementId,
         contact: contact,
         announcement: announcement
         );
 }
Example #24
0
 public Vehicle(
     string id,
     int year,
     EFuel fuel,
     EColor color,
     string modelId,
     DateTime?photoDate,
     Model model = null
     ) : this()
 {
     this.Id = string.IsNullOrWhiteSpace(id) ? RandomId.NewId() : id;
     this.SetData(
         year: year,
         fuel: fuel,
         color: color,
         modelId: modelId,
         photoDate: photoDate,
         model: model
         );
 }
        private async Task CreateVehicleWithImageAsync(string id)
        {
            var image  = new Bitmap(200, 200, PixelFormat.Format24bppRgb);
            var stream = new MemoryStream();

            image.Save(stream, ImageFormat.Bmp);
            byte[] imageBytes    = stream.ToArray();
            var    model         = EntitiesFactory.NewModel().Save();
            var    createVehicle = new CreateVehicle
            {
                Id      = id ?? RandomId.NewId(),
                FuelId  = EFuel.Flex,
                ColorId = EColor.Black,
                Year    = 2010,
                ModelId = model.Id
            };

            createVehicle.ImageBase64 = Convert.ToBase64String(imageBytes);
            await MutationsHandler.Handle(createVehicle);
        }
        public static IEnumerable <object[]> FinishReservationData()
        {
            yield return(new object[] { EStatusCode.InvalidData, new FinishReservation {
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new FinishReservation {
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new FinishReservation {
                                            Id = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.NotFound, new FinishReservation {
                                            Id = RandomId.NewId(), DateSale = DateTime.Now
                                        } });

            yield return(new object[] { EStatusCode.Success, new FinishReservation {
                                            Id = RandomId.NewId(), DateSale = DateTime.Now
                                        } });
        }
Example #27
0
        public BuilderFactory <Questor.Vehicle.Domain.Mutations.Vehicles.Entities.Vehicle> NewVehicle(
            string id      = null,
            string modelId = null,
            string brandId = null,
            int?year       = null,
            EFuel?fuel     = null,
            EColor?color   = null
            )
        {
            var model   = NewModel(id: modelId, brandId: brandId).Get();
            var vehicle = new Questor.Vehicle.Domain.Mutations.Vehicles.Entities.Vehicle(
                id: id ?? RandomId.NewId(),
                year: year ?? 2010,
                fuel: fuel ?? EFuel.Gasoline,
                color: color ?? EColor.Brown,
                modelId: model.Id,
                photoDate: null,
                model: model
                );

            return(new BuilderFactory <Questor.Vehicle.Domain.Mutations.Vehicles.Entities.Vehicle>(vehicle, DbContext));
        }
Example #28
0
        public static IEnumerable <object[]> UpdateAnnouncementData()
        {
            yield return(new object[] { EStatusCode.InvalidData, new UpdateAnnouncement {
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new UpdateAnnouncement {
                                            Id = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new UpdateAnnouncement {
                                            Id = RandomId.NewId(), PricePurchase = 30000
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new UpdateAnnouncement {
                                            Id = RandomId.NewId(), PricePurchase = 30000, PriceSale = 35000
                                        } });

            yield return(new object[] { EStatusCode.NotFound, new UpdateAnnouncement {
                                            Id = RandomId.NewId(), PricePurchase = 30000, PriceSale = 35000, VehicleId = RandomId.NewId()
                                        }, false, true });

            yield return(new object[] { EStatusCode.Success, new UpdateAnnouncement {
                                            Id = RandomId.NewId(), PricePurchase = 30000, PriceSale = 35000, VehicleId = RandomId.NewId()
                                        }, true, true });

            yield return(new object[] { EStatusCode.NotFound, new UpdateAnnouncement {
                                            Id = RandomId.NewId(), PricePurchase = 30000, PriceSale = 35000, VehicleId = RandomId.NewId()
                                        }, true, false });

            yield return(new object[] { EStatusCode.InvalidData, new UpdateAnnouncement {
                                            Id = RandomId.NewId(), PricePurchase = 0, PriceSale = 35000, VehicleId = RandomId.NewId()
                                        }, true, true });

            yield return(new object[] { EStatusCode.InvalidData, new UpdateAnnouncement {
                                            Id = RandomId.NewId(), PricePurchase = 30000, PriceSale = 0, VehicleId = RandomId.NewId()
                                        }, true, true });
        }
        public static IEnumerable <object[]> CreateReservationData()
        {
            yield return(new object[] { EStatusCode.InvalidData, new CreateReservation {
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new CreateReservation {
                                            Id = RandomId.NewId(), ContactName = RandomId.NewId(150)
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new CreateReservation {
                                            Id = RandomId.NewId(), ContactName = RandomId.NewId(150)
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new CreateReservation {
                                            Id = RandomId.NewId(), ContactName = RandomId.NewId(150), ContactPhone = RandomId.NewId(15)
                                        } });

            yield return(new object[] { EStatusCode.NotFound, new CreateReservation {
                                            Id = RandomId.NewId(), ContactName = RandomId.NewId(150), ContactPhone = RandomId.NewId(15), AnnouncementId = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.Conflict, new CreateReservation {
                                            Id = RandomId.NewId(), ContactName = RandomId.NewId(150), ContactPhone = RandomId.NewId(15), AnnouncementId = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.Success, new CreateReservation {
                                            Id = RandomId.NewId(), ContactName = RandomId.NewId(150), ContactPhone = RandomId.NewId(15), AnnouncementId = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new CreateReservation {
                                            Id = RandomId.NewId(), ContactName = RandomId.NewId(150), ContactPhone = RandomId.NewId(20), AnnouncementId = RandomId.NewId()
                                        } });

            yield return(new object[] { EStatusCode.InvalidData, new CreateReservation {
                                            Id = RandomId.NewId(), ContactName = RandomId.NewId(160), ContactPhone = RandomId.NewId(15), AnnouncementId = RandomId.NewId()
                                        } });
        }
Example #30
0
        public async Task <CommandResult> ExecuteAsync(CashbackCommandsHandler handler)
        {
            if (handler.DbContext.Genres != null && handler.DbContext.Genres.Count() > 0)
            {
                return(await Task.FromResult(new CommandResult(ErrorCode.None)));
            }

            if (string.IsNullOrEmpty(AccessToken))
            {
                Authorize();
            }

            IList <GenreViewModel> result = new List <GenreViewModel>();
            var defaultCashback           = new DefaultCashback();

            HttpClient httpClient = new HttpClient();
            var        genresUrls = new[] {
                "browse/categories/pop?country=BR",
                "browse/categories/mpb?country=BR",
                "browse/categories/classical?country=BR",
                "browse/categories/rock?country=BR"
            };

            var rows = 0;

            HttpResponseMessage response = null;

            foreach (var url in genresUrls)
            {
                httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", AccessToken);
                response = await httpClient.GetAsync("https://api.spotify.com/v1/" + url);

                var json = JsonConvert.DeserializeObject <GenreViewModel>(await response.Content.ReadAsStringAsync());

                if (response.IsSuccessStatusCode && !result.Any(c => c.Name == json.Name))
                {
                    result.Add(json);
                }
            }

            foreach (var item in result)
            {
                var id       = RandomId.NewId();
                var cashback = new List <CashbackCommand>();
                var lst      = defaultCashback.GetDefaultCashback(id, item.Name);
                lst.ForEach(f => cashback.Add(new CashbackCommand()
                {
                    Id = f.Id, GenreId = f.GenreId, DayOfWeek = f.DayOfWeek, Percent = f.Percent
                }));

                var cmd = new CreateGenreCommand()
                {
                    Id       = id,
                    Name     = item.Name,
                    Cashback = cashback
                };

                var rs = await handler.Handle(cmd);

                rows += rs.Rows;
            }

            return(await Task.FromResult(new CommandResult(rows, ErrorCode.None)));
        }