правки

This commit is contained in:
2025-04-08 14:27:46 +04:00
parent ea790d5d17
commit ac4aa4a146
10 changed files with 16 additions and 14 deletions

View File

@@ -18,7 +18,7 @@ public class TourDataModel(string id, string tourName, string tourCountry, doubl
public string TourName { get; private set; } = tourName;
public string TourCountry { get; private set; } = tourCountry;
public double Price { get; private set; } = price;
public TourType Type { get; private set; } = tourType;
public TourType TourType { get; private set; } = tourType;
public void Validate()
{
@@ -32,7 +32,7 @@ public class TourDataModel(string id, string tourName, string tourCountry, doubl
throw new ValidationException("Field TourCountry is empty");
if (Price <= 0)
throw new ValidationException("Field Price is less than or equal to 0");
if (Type == TourType.None)
if (TourType == TourType.None)
throw new ValidationException("Field Type is empty");
}
}

View File

@@ -122,7 +122,7 @@ public class AgencyStorageContract : IAgencyStorageContract
foreach (SaleTourDataModel sale_tour in saleDataModel.Tours)
{
var tour = _dbContext.Tours.FirstOrDefault(x => x.Id == sale_tour.TourId);
var agency = _dbContext.Agencies.FirstOrDefault(x => x.Type == tour.Type && x.Count >= sale_tour.Count);
var agency = _dbContext.Agencies.FirstOrDefault(x => x.Type == tour.TourType && x.Count >= sale_tour.Count);
if (agency == null)
{

View File

@@ -24,7 +24,9 @@ internal class TourStorageContract : ITourStorageContract
_dbContext = dbContext;
var config = new MapperConfiguration(cfg =>
{
cfg.AddMaps(typeof(Tour));
cfg.CreateMap<Tour, TourDataModel>();
cfg.CreateMap<TourDataModel, Tour>();
cfg.CreateMap<TourHistory, TourHistoryDataModel>(); ;
});
_mapper = new Mapper(config);
}

View File

@@ -18,7 +18,7 @@ public class Tour
public required string TourName { get; set; }
public string? TourCountry { get; set; }
public double Price { get; set; }
public required TourType Type { get; set; }
public required TourType TourType { get; set; }
[ForeignKey("TourId")]
public List<SaleTour>? SaleTours { get; set; }
[ForeignKey("TourId")]

View File

@@ -250,7 +250,7 @@ internal class TourBusinessLogicContractTests
.Callback((TourDataModel x) =>
{
flag = x.Id == record.Id && x.TourName == record.TourName && x.TourCountry == record.TourCountry
&& x.Price == record.Price && x.Type == record.Type;
&& x.Price == record.Price && x.TourType == record.TourType;
});
//Act
_tourBusinessLogicContract.InsertTour(record);
@@ -313,7 +313,7 @@ internal class TourBusinessLogicContractTests
.Callback((TourDataModel x) =>
{
flag = x.Id == record.Id && x.TourName == record.TourName && x.TourCountry == record.TourCountry
&& x.Price == record.Price && x.Type == record.Type;
&& x.Price == record.Price && x.TourType == record.TourType;
});
//Act
_tourBusinessLogicContract.UpdateTour(record);

View File

@@ -78,7 +78,7 @@ internal class TourDataModelTests
Assert.That(tour.TourName, Is.EqualTo(tourName));
Assert.That(tour.TourCountry, Is.EqualTo(tourCountry));
Assert.That(tour.Price, Is.EqualTo(price));
Assert.That(tour.Type, Is.EqualTo(tourType));
Assert.That(tour.TourType, Is.EqualTo(tourType));
});
}

View File

@@ -125,7 +125,7 @@ internal class AgencyStorageContractTests : BaseStorageContractTest
private Tour InsertTourToDatabaseAndReturn(string id, string name, TourType type)
{
var tour = new Tour { Id = id, TourName = name, Type = type };
var tour = new Tour { Id = id, TourName = name, TourType = type };
MagicCarpetDbContext.Tours.Add(tour);
MagicCarpetDbContext.SaveChanges();
return tour;

View File

@@ -211,7 +211,7 @@ internal class SaleStorageContractTests : BaseStorageContractTest
private Tour InsertTourToDatabaseAndReturn(string tourName = "test", TourType tourType = TourType.Sightseeing, double price = 1)
{
var tour = new Tour() { Id = Guid.NewGuid().ToString(), TourName = tourName, Type = tourType, Price = price };
var tour = new Tour() { Id = Guid.NewGuid().ToString(), TourName = tourName, TourType = tourType, Price = price };
MagicCarpetDbContext.Tours.Add(tour);
MagicCarpetDbContext.SaveChanges();
return tour;

View File

@@ -98,7 +98,7 @@ internal class SuppliesStorageContractTests : BaseStorageContractTest
private Tour InsertTourToDatabaseAndReturn()
{
var tour = new Tour { Id = Guid.NewGuid().ToString(), TourName = "Test Tour", Type = TourType.Ski };
var tour = new Tour { Id = Guid.NewGuid().ToString(), TourName = "Test Tour", TourType = TourType.Ski };
MagicCarpetDbContext.Tours.Add(tour);
MagicCarpetDbContext.SaveChanges();
return tour;

View File

@@ -168,7 +168,7 @@ internal class TourStorageContractTests : BaseStorageContractTest
private Tour InsertTourToDatabaseAndReturn(string id, string tourName = "test", string tourCountry = "country", TourType tourType = TourType.Beach, double price = 1)
{
var tour = new Tour() { Id = id, TourName = tourName, TourCountry = tourCountry, Type = tourType, Price = price };
var tour = new Tour() { Id = id, TourName = tourName, TourCountry = tourCountry, TourType = tourType, Price = price };
MagicCarpetDbContext.Tours.Add(tour);
MagicCarpetDbContext.SaveChanges();
return tour;
@@ -190,7 +190,7 @@ internal class TourStorageContractTests : BaseStorageContractTest
Assert.That(actual.Id, Is.EqualTo(expected.Id));
Assert.That(actual.TourName, Is.EqualTo(expected.TourName));
Assert.That(actual.TourCountry, Is.EqualTo(expected.TourCountry));
Assert.That(actual.Type, Is.EqualTo(expected.Type));
Assert.That(actual.TourType, Is.EqualTo(expected.TourType));
Assert.That(actual.Price, Is.EqualTo(expected.Price));
});
}
@@ -208,7 +208,7 @@ internal class TourStorageContractTests : BaseStorageContractTest
Assert.That(actual.Id, Is.EqualTo(expected.Id));
Assert.That(actual.TourName, Is.EqualTo(expected.TourName));
Assert.That(actual.TourCountry, Is.EqualTo(expected.TourCountry));
Assert.That(actual.Type, Is.EqualTo(expected.Type));
Assert.That(actual.TourType, Is.EqualTo(expected.TourType));
Assert.That(actual.Price, Is.EqualTo(expected.Price));
});
}