Ejemplo n.º 1
0
        public void SaveDuplicate_WhenTryToSaveDuplicates_ShouldThrowException()
        {
            ////Arrange
            var eventRepository = new SqlRepository <Event>();

            var newEntity1 = new Event
            {
                Date        = DateTime.Now.Date.AddDays(1).AddHours(15),
                Description = "EventDescription1",
                LayoutId    = 1,
                Name        = "EventName1",
            };

            var newEntity2 = new Event
            {
                Date        = DateTime.Now.Date.AddDays(1).AddHours(15),
                Description = "EventDescription2",
                LayoutId    = 1,
                Name        = "EventName2",
            };

            ////Act
            void TestAction()
            {
                eventRepository.Save(newEntity1);
                eventRepository.Save(newEntity2);
            }

            ////Assert
            Assert.Throws <NotUniqueException>(TestAction);

            ////CleanUp
            eventRepository.Delete(newEntity1.Id);
        }
Ejemplo n.º 2
0
        public void SaveDuplicate_WhenTryToSaveDuplicates_ShouldThrowException()
        {
            ////Arrange
            var layoutRepository = new SqlRepository <Layout>();

            var newEntity1 = new Layout
            {
                VenueId     = 1,
                Description = "Third layout",
            };

            var newEntity2 = new Layout
            {
                VenueId     = 1,
                Description = "Third layout",
            };

            ////Act
            void TestAction()
            {
                layoutRepository.Save(newEntity1);
                layoutRepository.Save(newEntity2);
            }

            ////Assert
            Assert.Throws <NotUniqueException>(TestAction);

            ////CleanUp
            layoutRepository.Delete(newEntity1.Id);
        }
Ejemplo n.º 3
0
        public void Update_WhenUpdatePerforms_ShouldReadTheSame()
        {
            ////Arrange
            var eventRepository = new SqlRepository <Event>();

            var newEntity1 = new Event
            {
                Date        = DateTime.Now.Date.AddDays(1).AddHours(15),
                Description = "EventDescription1",
                LayoutId    = 1,
                Name        = "EventName1",
            };

            var newEntity2 = new Event
            {
                Date        = DateTime.Now.Date.AddDays(1).AddHours(15),
                Description = "EventDescription2",
                LayoutId    = 1,
                Name        = "EventName2",
            };

            eventRepository.Save(newEntity1);
            newEntity2.Id = newEntity1.Id;

            ////Act
            eventRepository.Save(newEntity2);

            ////Assert
            newEntity2.Should().BeEquivalentTo(eventRepository.ReadOne(newEntity1.Id));

            ////CleanUp
            eventRepository.Delete(newEntity1.Id);
        }
Ejemplo n.º 4
0
        public void Delete_WhenDeletePerforms_ShouldReadAllWithoutDeletedEntity()
        {
            ////Arrange
            var eventRepository = new SqlRepository <Event>();

            var someEntity = new Event
            {
                Date        = DateTime.Now.Date.AddDays(1).AddHours(15),
                Description = "EventDescription1",
                LayoutId    = 1,
                Name        = "EventName1",
            };

            eventRepository.Save(someEntity);

            var venueList = eventRepository.ReadAll().ToList();

            venueList.RemoveAll(x => x.Id == someEntity.Id);

            ////Act
            eventRepository.Delete(someEntity.Id);

            ////Assert
            venueList.Should().BeEquivalentTo(eventRepository.ReadAll().ToList());
        }
        public void Delete(SubSession sessionSubtotal)
        {
            t_sessionsubtotal entity =
                _sqlRepository.Find(_ => _.SessionSubtotalId == sessionSubtotal.SessionSubtotalId).Single();

            _sqlRepository.Delete(entity);
        }
        public void Delete(ShooterParticipation shooterParticipation)
        {
            t_shooterparticipation entity =
                _sqlRepository.Find(_ => _.ShooterParticipationId == shooterParticipation.ShooterParticipationId).Single();

            _sqlRepository.Delete(entity);
        }
Ejemplo n.º 7
0
        public void Delete_WhenDeletePerforms_ShouldReadAllWithoutDeletedEntity()
        {
            ////Arrange
            var areaRepository = new SqlRepository <Area>();

            var someEntity = new Area
            {
                LayoutId    = 2,
                Description = "Second area of second layout",
                CoordX      = 3,
                CoordY      = 4,
            };

            areaRepository.Save(someEntity);

            var venueList = areaRepository.ReadAll().ToList();

            venueList.RemoveAll(x => x.Id == someEntity.Id);

            ////Act
            areaRepository.Delete(someEntity.Id);

            ////Assert
            venueList.Should().BeEquivalentTo(areaRepository.ReadAll().ToList());
        }
Ejemplo n.º 8
0
        public void SaveDuplicate_WhenTryToSaveDuplicates_ShouldThrowException()
        {
            ////Arrange
            var venueRepository = new SqlRepository <Venue>();

            var newVenue1 = new Venue
            {
                Description = "Second venue",
                Address     = "Second venue address",
                Phone       = "+375(29)123-45-67",
            };

            var newVenue2 = new Venue
            {
                Description = "Second venue",
                Address     = "Second venue address",
                Phone       = "+375(29)123-45-67",
            };

            ////Act
            void TestAction()
            {
                venueRepository.Save(newVenue1);
                venueRepository.Save(newVenue2);
            }

            ////Assert
            Assert.Throws <NotUniqueException>(TestAction);

            ////CleanUp
            venueRepository.Delete(newVenue1.Id);
        }
        public void Create_Insert_Get_Delete()
        {
            var model = new MyModel();

            model.Name = Guid.NewGuid().ToString();

            m_SqlRepository.Insert(model);

            var existingId = model.Id;

            model = m_SqlRepository.Get <MyModel>(i => i.Id == existingId);

            Assert.IsNotNull(model);

            var name = Guid.NewGuid().ToString();

            model.Name = name;

            m_SqlRepository.Update(model);

            model = m_SqlRepository.Get <MyModel>(i => i.Id == existingId);

            Assert.AreEqual(name, model.Name);

            m_SqlRepository.Delete(model);

            model = m_SqlRepository.Get <MyModel>(i => i.Id == existingId);

            Assert.IsNull(model);
        }
Ejemplo n.º 10
0
        internal virtual void Delete(Guid id)
        {
            var entity = Repository.Find(e => e.Id == id).SingleOrDefault();

            if (entity != null)
            {
                Repository.Delete(entity);
            }
        }
Ejemplo n.º 11
0
        public void Save_WhenEntitySaved_ShouldReadTheSame()
        {
            ////Arrange
            var layoutRepository = new SqlRepository <Layout>();

            var newEntity = new Layout
            {
                VenueId     = 1,
                Description = "Third layout",
            };

            ////Act
            layoutRepository.Save(newEntity);

            ////Assert
            newEntity.Should().BeEquivalentTo(layoutRepository.ReadOne(newEntity.Id));

            ////CleanUp
            layoutRepository.Delete(newEntity.Id);
        }
Ejemplo n.º 12
0
 private void btnSil_Click(object sender, EventArgs e)
 {
     try
     {
         Musteri musteri = repoMusteri.Listele(w => w.ID == secilenMusteriID).FirstOrDefault();
         if (musteri != null)
         {
             repoMusteri.Delete(musteri);
             Temizle();
         }
         else
         {
             MessageBox.Show("Boyle Bir Musteri Yok", "UYARI!");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 13
0
 private void btnSil_Click(object sender, EventArgs e)
 {
     try
     {
         Tedarikci tedarikci = repoTedarikci.Listele(w => w.ID == secilenTedarikciID).First();
         if (tedarikci != null)
         {
             repoTedarikci.Delete(tedarikci);
             Temizle();
         }
         else
         {
             MessageBox.Show("Boyle Bir Tedarikci Yok", "UYARI!");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 14
0
        public void Save_WhenEntitySaved_ShouldReadTheSame()
        {
            ////Arrange
            var venueRepository = new SqlRepository <Venue>();

            var newVenue = new Venue
            {
                Description = "Second venue",
                Address     = "Second venue address",
                Phone       = "+375(29)123-45-67",
            };

            ////Act
            venueRepository.Save(newVenue);

            ////Assert
            newVenue.Should().BeEquivalentTo(venueRepository.ReadOne(newVenue.Id));

            ////CleanUp
            venueRepository.Delete(newVenue.Id);
        }
Ejemplo n.º 15
0
        public void Save_WhenEntitySaved_ShouldReadTheSame()
        {
            ////Arrange
            var seatRepository = new SqlRepository <Seat>();

            var newEntity = new Seat
            {
                AreaId = 1,
                Row    = 1,
                Number = 4,
            };

            ////Act
            seatRepository.Save(newEntity);

            ////Assert
            newEntity.Should().BeEquivalentTo(seatRepository.ReadOne(newEntity.Id));

            ////CleanUp
            seatRepository.Delete(newEntity.Id);
        }
Ejemplo n.º 16
0
 public ActionResult ConfirmDelete(int id)
 {
     try
     {
         Product pToDelete = context.FindById(id);
         if (pToDelete == null)
         {
             return(HttpNotFound());
         }
         else
         {
             context.Delete(id);
             context.Commit();
             return(RedirectToAction("Index"));
         }
     }
     catch (Exception)
     {
         return(HttpNotFound());
     }
 }
Ejemplo n.º 17
0
 private void btnSil_Click(object sender, EventArgs e)
 {
     try
     {
         Urun urun = repoUrun.Listele(w => w.ID == urunID).FirstOrDefault();
         if (urun != null)
         {
             panel1.Enabled = false;
             repoUrun.Delete(urun);
             Temizle();
             Yukle();
         }
         else
         {
             MessageBox.Show("Boyle Bir Ürün Yok", "UYARI!");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Ejemplo n.º 18
0
        public void Save_WhenEntitySaved_ShouldReadTheSame()
        {
            ////Arrange
            var areaRepository = new SqlRepository <Area>();

            var newEntity = new Area
            {
                LayoutId    = 2,
                Description = "Second area of second layout",
                CoordX      = 3,
                CoordY      = 4,
            };

            ////Act
            areaRepository.Save(newEntity);

            ////Assert
            newEntity.Should().BeEquivalentTo(areaRepository.ReadOne(newEntity.Id));

            ////CleanUp
            areaRepository.Delete(newEntity.Id);
        }
Ejemplo n.º 19
0
        public void Delete_WhenDeletePerforms_ShouldReadAllWithoutDeletedEntity()
        {
            ////Arrange
            var layoutRepository = new SqlRepository <Layout>();

            var someEntity = new Layout
            {
                VenueId     = 1,
                Description = "Third layout",
            };

            layoutRepository.Save(someEntity);

            var venueList = layoutRepository.ReadAll().ToList();

            venueList.RemoveAll(x => x.Id == someEntity.Id);

            ////Act
            layoutRepository.Delete(someEntity.Id);

            ////Assert
            venueList.Should().BeEquivalentTo(layoutRepository.ReadAll().ToList());
        }
Ejemplo n.º 20
0
        public void Delete_WhenDeletePerforms_ShouldReadAllWithoutDeletedEntity()
        {
            ////Arrange
            var venueRepository = new SqlRepository <Venue>();

            var someVenue = new Venue
            {
                Description = "Second venue",
                Address     = "Second venue address",
                Phone       = "+375(29)123-45-67",
            };

            venueRepository.Save(someVenue);

            var venueList = venueRepository.ReadAll().ToList();

            venueList.RemoveAll(x => x.Id == someVenue.Id);

            ////Act
            venueRepository.Delete(someVenue.Id);

            ////Assert
            venueList.Should().BeEquivalentTo(venueRepository.ReadAll().ToList());
        }
Ejemplo n.º 21
0
        public void Delete_WhenDeletePerforms_ShouldReadAllWithoutDeletedEntity()
        {
            ////Arrange
            var seatRepository = new SqlRepository <Seat>();

            var someEntity = new Seat
            {
                AreaId = 1,
                Row    = 1,
                Number = 4,
            };

            seatRepository.Save(someEntity);

            var venueList = seatRepository.ReadAll().ToList();

            venueList.RemoveAll(x => x.Id == someEntity.Id);

            ////Act
            seatRepository.Delete(someEntity.Id);

            ////Assert
            venueList.Should().BeEquivalentTo(seatRepository.ReadAll().ToList());
        }
Ejemplo n.º 22
0
        public void Delete(Shot shot)
        {
            t_shot entity = _sqlRepository.Find(_ => _.ShotId == shot.ShotId).Single();

            _sqlRepository.Delete(entity);
        }
Ejemplo n.º 23
0
        public void Delete(Person person)
        {
            t_person entity = _sqlRepository.Find(_ => _.PersonId == person.PersonId).Single();

            _sqlRepository.Delete(entity);
        }
        public void Delete(ShooterCollection shooterCollection)
        {
            t_shootercollection entity = _sqlRepository.Find(_ => _.ShooterCollectionId == shooterCollection.ShooterCollectionId).Single();

            _sqlRepository.Delete(entity);
        }
Ejemplo n.º 25
0
        public void Save_WhenEntitySaved_ShouldReadTheSame()
        {
            ////Arrange
            _configurationManager.LoadDataBase();

            var @event = new Event
            {
                Date        = DateTime.Now.Date.AddDays(1).AddHours(15),
                Description = "EventDescription1",
                LayoutId    = 1,
                Name        = "EventName1",
            };

            var eventAreaList = new List <EventArea>
            {
                new EventArea
                {
                    Id          = 1,
                    EventId     = 1,
                    Description = "First area of first layout",
                    CoordX      = 1,
                    CoordY      = 1,
                    Price       = 0,
                },
                new EventArea
                {
                    Id          = 2,
                    EventId     = 1,
                    Description = "Second area of first layout",
                    CoordX      = 1,
                    CoordY      = 1,
                    Price       = 0,
                },
            };

            var eventSeatList = new List <EventSeat>
            {
                new EventSeat
                {
                    Id          = 1,
                    EventAreaId = 1,
                    Row         = 1,
                    Number      = 1,
                    State       = 0,
                },
                new EventSeat
                {
                    Id          = 2,
                    EventAreaId = 1,
                    Row         = 1,
                    Number      = 2,
                    State       = 0,
                },

                new EventSeat
                {
                    Id          = 3,
                    EventAreaId = 1,
                    Row         = 1,
                    Number      = 3,
                    State       = 0,
                },
                new EventSeat
                {
                    Id          = 4,
                    EventAreaId = 1,
                    Row         = 2,
                    Number      = 2,
                    State       = 0,
                },
                new EventSeat
                {
                    Id          = 5,
                    EventAreaId = 1,
                    Row         = 2,
                    Number      = 1,
                    State       = 0,
                },
                new EventSeat
                {
                    Id          = 6,
                    EventAreaId = 2,
                    Row         = 1,
                    Number      = 1,
                    State       = 0,
                },
            };

            var eventRepository     = new SqlRepository <Event>();
            var eventAreaRepository = new SqlRepository <EventArea>();
            var eventSeatRepository = new SqlRepository <EventSeat>();

            ////Act
            eventRepository.Save(@event);

            ////Assert
            @event.Should().BeEquivalentTo(eventRepository.ReadOne(@event.Id));
            eventAreaList.Should().BeEquivalentTo(eventAreaRepository.ReadAll().ToList());
            eventSeatList.Should().BeEquivalentTo(eventSeatRepository.ReadAll().ToList());

            ////CleanUp
            eventRepository.Delete(@event.Id);
        }
        public void Delete(CollectionShooter collectionShooter)
        {
            t_collectionshooter entity = _sqlRepository.Find(_ => _.CollectionShooterId == collectionShooter.CollectionShooterId).Single();

            _sqlRepository.Delete(entity);
        }
Ejemplo n.º 27
0
        public void Delete(Session session)
        {
            t_session entity = _sqlRepository.Find(_ => _.SessionId == session.SessionId).Single();

            _sqlRepository.Delete(entity);
        }
Ejemplo n.º 28
0
        public void Delete(Shooter shooter)
        {
            t_shooter entity = _sqlRepository.Find(_ => _.ShooterId == shooter.ShooterId).Single();

            _sqlRepository.Delete(entity);
        }
Ejemplo n.º 29
0
        static async Task Main(string[] args)
        {
            string input = "";
            Dictionary <string, Category> categoryLookup = new Dictionary <string, Category>()
            {
                { "wishlist", Category.Wishlist },
                { "collection", Category.Collection }
            };

            IFileAccess      azureFileAccess = new AzureFileAccess(Constants.AzureFileConnectionString, Constants.AzureFileShareName);
            IFileAccess      localFileAccess = new LocalFileAccess();
            IAlbumRepository repository      = new SqlRepository(Constants.DbConnectionString);

            // IAlbumRepository repository = new JsonRepository(Constants.AzureFileFilepath, azureFileAccess);
            //IAlbumRepository repository = new JsonRepository(Constants.LocalFilePath, localFileAccess);
            //IAlbumRepository repository = new CosmosRepository(Constants.CosmosEndpointUri, Constants.CosmosPrimaryKey, Constants.CosmosDatabaseId, Constants.CosmosContainerId);

            while (input != "9")
            {
                Console.WriteLine("Main Menu");
                Console.WriteLine("1. Enter new Album");
                Console.WriteLine("2. Edit Album");
                Console.WriteLine("3. Display All");
                Console.WriteLine("4. Display Wishlist");
                Console.WriteLine("5. Display Collection");
                Console.WriteLine("6. Display filtered albums");
                Console.WriteLine("7. Display Totals");
                Console.WriteLine("8. Delete Album");
                Console.WriteLine("9. Exit");
                input = Console.ReadLine();

                if (input == "1")
                {
                    Console.Write("Artist: ");
                    string artist = Console.ReadLine();
                    Console.Write("Title: ");
                    string title = Console.ReadLine();
                    Console.Write("Year: ");
                    int year = 0;
                    int.TryParse(Console.ReadLine(), out year);
                    Console.Write("Format: ");
                    string format = Console.ReadLine();
                    Console.Write("Store: ");
                    string  store = Console.ReadLine();
                    decimal price = 0;
                    Console.Write("Price: ");
                    decimal.TryParse(Console.ReadLine(), out price);
                    Console.Write("Symbol: ");
                    string symbol = Console.ReadLine();
                    Console.Write("Location: ");
                    string   location = Console.ReadLine();
                    Category c        = Category.Wishlist;
                    categoryLookup.TryGetValue(location.ToLower(), out c);

                    await repository.Add(new Album()
                    {
                        Id       = 0,
                        Artist   = artist,
                        Title    = title,
                        Year     = year == 0 ? "" : year.ToString(),
                        Format   = format,
                        Store    = store,
                        Price    = price,
                        Symbol   = symbol,
                        Location = c
                    });
                }

                else if (input == "2")
                {
                    int id = 0;
                    Console.WriteLine("Edit Album");
                    Console.Write("Id to edit: ");
                    int.TryParse(Console.ReadLine(), out id);

                    Album e = await repository.GetBy(id);

                    if (e != null)
                    {
                        string   artist   = e.Artist;
                        string   title    = e.Title;
                        string   year     = e.Year;
                        string   format   = e.Format;
                        string   store    = e.Store;
                        decimal  price    = e.Price;
                        string   symbol   = e.Symbol;
                        Category location = e.Location;

                        Console.Write("Artist (" + artist + "): ");
                        string artistIn = Console.ReadLine();
                        if (!string.IsNullOrEmpty(artistIn))
                        {
                            e.Artist = artistIn;
                        }
                        Console.Write("Title (" + title + "): ");
                        string titleIn = Console.ReadLine();
                        if (!string.IsNullOrEmpty(titleIn))
                        {
                            e.Title = titleIn;
                        }
                        Console.Write("Year (" + year + "): ");
                        string yearIn = Console.ReadLine();
                        if (!string.IsNullOrEmpty(yearIn))
                        {
                            int y = 0;
                            int.TryParse(yearIn, out y);

                            e.Year = y == 0 ? "" : y.ToString();
                        }
                        Console.Write("Format (" + format + "): ");
                        string formatIn = Console.ReadLine();
                        if (!string.IsNullOrEmpty(formatIn))
                        {
                            e.Format = formatIn;
                        }
                        Console.Write("Store (" + store + "): ");
                        string storeIn = Console.ReadLine();
                        if (!string.IsNullOrEmpty(storeIn))
                        {
                            e.Store = storeIn;
                        }

                        Console.Write("Price (" + price + "): ");
                        string priceIn = Console.ReadLine();
                        if (!string.IsNullOrEmpty(priceIn))
                        {
                            decimal p = 0;
                            decimal.TryParse(priceIn, out p);

                            e.Price = p;
                        }

                        Console.Write("Symbol (" + symbol + "): ");
                        string symbolIn = Console.ReadLine();
                        if (!string.IsNullOrEmpty(symbolIn))
                        {
                            e.Symbol = symbolIn;
                        }
                        Console.Write("Location (" + location + "): ");
                        string locationIn = Console.ReadLine();
                        if (!string.IsNullOrEmpty(locationIn))
                        {
                            Category c = Category.Wishlist;
                            categoryLookup.TryGetValue(locationIn.ToLower(), out c);
                            e.Location = c;
                        }

                        await repository.Edit(e);
                    }
                    else
                    {
                        Console.WriteLine("Could not find album with id = " + id);
                    }
                }

                else if (input == "3")
                {
                    printAlbums(await repository.GetAll());
                }
                else if (input == "4")
                {
                    printAlbums(repository.GetAll().Result.Where(a => a.Location == Category.Wishlist));
                }
                else if (input == "5")
                {
                    printAlbums(repository.GetAll().Result.Where(a => a.Location == Category.Collection));
                }
                else if (input == "6")
                {
                    Console.Write("Filter Expression: ");
                    string filter = Console.ReadLine();

                    // var result = repository.GetFilteredAlbums(filter);
                    var result = GetFilteredAlbums(filter, repository.GetAll().Result);
                    printAlbums(result);
                }
                else if (input == "7")
                {
                    decimal wishListTotal   = repository.GetAll().Result.Where(a => a.Location == Category.Wishlist).Sum(a => a.Price);
                    decimal collectionTotal = repository.GetAll().Result.Where(a => a.Location == Category.Collection).Sum(a => a.Price);

                    Console.WriteLine("Wishlist total: " + wishListTotal.ToString("C", CultureInfo.CurrentCulture));
                    Console.WriteLine("Collection total: " + collectionTotal.ToString("C", CultureInfo.CurrentCulture));
                }
                else if (input == "8")
                {
                    Console.WriteLine("Delete album");
                    Console.Write("Id to delete: ");
                    string id       = Console.ReadLine();
                    int    parsedId = 0;
                    if (!int.TryParse(id, out parsedId))
                    {
                        Console.WriteLine("Id must be a number");
                        continue;
                    }
                    var a = await repository.GetBy(parsedId);

                    if (a != null)
                    {
                        Console.WriteLine("*** WARNING *** This operation cannot be undone. Please type the name of the album to delete below");
                        string titleToDelete = Console.ReadLine();
                        if (a.Title == titleToDelete)
                        {
                            await repository.Delete(a.Id);
                        }
                        else
                        {
                            Console.WriteLine("Album not found, nothing deleted");
                        }
                    }
                }

                else if (input == "9")
                {
                    Console.WriteLine("Bye");
                }
            }
        }