public void TestGetPackagesWithRecipientAndStatus_WithTestData_ShoudGetAllPackagesWithRecipientAndStatus() { var factory = new PandaDbContextFactory(); var context = factory.CreatePandaDbContext(); var services = new PackagesService(context); SeedDbWithPackages(context); SeedDbWithPackageStuses(context); SeedDbWithRecipients(context); MakeTheConnectionBetweenTheEntities(context); var expectedData = context.Packages .Include(package => package.Recipient) .Include(package => package.Status) .ToList(); var actualData = services.GetPackagesWithRecipientAndStatus().ToList(); foreach (var package in actualData) { Assert.Contains(expectedData, x => x.Recipient.Id == package.Recipient.Id && x.Status == package.Status); } }
public void TestGetAllUsers_WithoutAnyData() { var inMemoryContext = this.InitializeInMemoryDb(); var packageService = new PackagesService(inMemoryContext); this.ClearData(inMemoryContext); var actualData = packageService.GetAllPackages().ToList(); Assert.True(actualData.Count() == 0); inMemoryContext.Dispose(); }
public async Task TestGetAllUsers_NonExistingUser() { var inMemoryContext = this.InitializeInMemoryDb(); var packageService = new PackagesService(inMemoryContext); // SeedTestData(inMemoryContext); string testUserId = "TestUser3"; var actualData = await packageService .GetPackageAsync(testUserId); Assert.Null(actualData); inMemoryContext.Dispose(); }
public void TestGetPackageStatus_WithTestData_ShoudGetPackageStatusWithName() { var factory = new PandaDbContextFactory(); var context = factory.CreatePandaDbContext(); var services = new PackagesService(context); SeedDbWithPackageStuses(context); var packageStatus = context.PackageStatus.FirstOrDefault(); var actualData = services.GetPackageStatus(packageStatus.Name); var expectedData = packageStatus; Assert.True(actualData.Id == expectedData.Id && actualData.Name == expectedData.Name); }
public void TestAddPackage_WithTestData_ShoudAddNewPackageInToDb() { var factory = new PandaDbContextFactory(); var context = factory.CreatePandaDbContext(); var services = new PackagesService(context); services.AddPackage(new Package()); var packeges = context.Packages.ToList(); var actualData = packeges.Count; var expectedData = 1; Assert.True(expectedData == actualData, "PackagesService AddPackage() method does not work porperly!"); }
public void TestGetPackage_WithTestData_ShoudGetPackageWithId() { var factory = new PandaDbContextFactory(); var context = factory.CreatePandaDbContext(); var services = new PackagesService(context); SeedDbWithPackages(context); var package = context.Packages.FirstOrDefault(); var actualData = services.GetPackage(package.Id); var expectedData = package; Assert.True(actualData.Id == expectedData.Id && actualData.Weight == expectedData.Weight && actualData.Description == expectedData.Description && actualData.ShippingAddress == expectedData.ShippingAddress); }
public void TestGetAllPackages_ShouldReturn_OnlyIfNotDeleted() { var inMemoryContext = this.InitializeInMemoryDb(); var packageService = new PackagesService(inMemoryContext); var expectedData = GetTestData(); this.SeedTestData(inMemoryContext); var actualData = packageService.GetAllPackages().ToList(); Assert.NotEqual(expectedData.Count, actualData.Count); Assert.Single(actualData); foreach (var actualPackage in actualData) { Assert.True(expectedData.Any(user => actualPackage.Id == user.Id && actualPackage.ShippingAddress == user.ShippingAddress && actualPackage.Description == user.Description), "Wrong"); } inMemoryContext.Dispose(); }
public async Task TestGetAllUsers_UserDetailsMatch() { var inMemoryContext = this.InitializeInMemoryDb(); var packageService = new PackagesService(inMemoryContext); this.ClearData(inMemoryContext); this.SeedTestData(inMemoryContext); var testPackageId = "TestId2"; var expectedData = GetTestData() .SingleOrDefault(package => package.Id == testPackageId); var actualData = await packageService .GetPackageAsync(testPackageId); Assert.Equal(expectedData.Description, actualData.Description); inMemoryContext.Dispose(); }
public void TestUpdatePackage_WithTestData_ShoudUpdatePackage() { var factory = new PandaDbContextFactory(); var context = factory.CreatePandaDbContext(); var services = new PackagesService(context); double newWeight = 9999; SeedDbWithPackages(context); var package = context.Packages.FirstOrDefault(); package.Weight = newWeight; services.UpdatePackage(package); var actualData = context.Packages.FirstOrDefault().Weight; var expectedData = newWeight; Assert.True(expectedData == actualData, "PackagesService UpdatePackage() method does not work porperly!"); }
public void TestGetAllUsers_WithTwoTestUsers_ShouldReturnAllUsers() { var options = new DbContextOptionsBuilder <PandaDbContext>() .UseInMemoryDatabase(databaseName: Guid.NewGuid().ToString()) .Options; var context = new PandaDbContext(options); SeedTestData(context); var service = new PackagesService(context); var expectedData = GetTestPackages(); var actualData = service.GetPackagesWithRecipientAndStatus(); Assert.Equal(expectedData.Count, actualData.Count()); foreach (var package in actualData) { Assert.True(expectedData.Any(p => package.Recipient.UserName == p.Recipient.UserName && package.Status.Name == p.Status.Name), "PackagesService GetPackagesWithRecipientAndStatus() method not correct!"); } }
public MessagesFacade() { _messagesService = new MessagesService(); _luisService = new LuisService(); _packagesService = new PackagesService(); }