Пример #1
0
		public async Task ViewModel_ShouldReturnCorrectValue(
		  IFixture fixture,
			TestSchedulers scheduler)
		{
			//arrange
			const int insertionIndex = 5;
			var initialList = fixture.CreateMany<int>(10).ToArray();
			var addedList = fixture.CreateMany<int>(10).ToArray();
			var expected = initialList.Take(insertionIndex)
									  .Concat(addedList.Reverse())
									  .Concat(initialList.Skip(insertionIndex))
									  .ToArray();
			var notifications = scheduler.CreateColdObservable(addedList.Select((i, ii) => OnNext(Subscribed + 1 + ii, i)).ToArray());
			var sut = new UpdatableObservableViewModelBuilderOptions<int, int[], int>(
				_ => { },
				ct => Task.FromResult(initialList),
				() => notifications,
				scheduler,
				scheduler,
				scheduler)
				.UpdateAction((i, o) => () => o.Insert(insertionIndex, i))
				.ToViewModel();

			//act

			scheduler.Start();
			await sut.RefreshAsync();
			scheduler.AdvanceBy(Disposed);
			var actual = ((IObservableViewModel<ObservableCollection<int>>)sut).CurrentValue;
			//assert

			actual.ShouldAllBeEquivalentTo(expected);
		}
        public async Task DeleteCategoryAsync_OneElementDelete(
            [Frozen] Mock <IProductCatalogueContext> context,
            ProductCategoryService service,
            IFixture fixture)
        {
            var categories = fixture.CreateMany <DbProductCategory>(5).ToList();
            var products   = fixture.CreateMany <CatalogueProduct>(5).ToList();

            categories[0].IsDeleted = true;
            context.Setup(x => x.Products).ReturnsEntitySet(products);
            context.Setup(x => x.Categories).ReturnsEntitySet(categories);

            await service.DeleteCategoryAsync(categories[0].Id);

            var result = await service.GetCategoriesAsync(0, 6);

            result.Count.Should().Be(4);
        }
Пример #3
0
        public async Task DeleteHiveTestAsync_AcceptsWrongId_ThrowsException([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            var hiveId = 1;
            var hives  = fixture.CreateMany <StoreHive>(1).ToList();

            hives[0].Id = 2;
            context.Setup(s => s.Hives).ReturnsEntitySet(hives);
            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.DeleteHiveAsync(hiveId));
        }
        public async Task UpdateCategoryAsync_RequestedResourceHasConflictException(
            [Frozen] Mock <IProductCatalogueContext> context,
            ProductCategoryService service,
            IFixture fixture)
        {
            var categories     = fixture.CreateMany <DbProductCategory>(5).ToList();
            var products       = fixture.CreateMany <CatalogueProduct>(5).ToList();
            var updateCategory = new UpdateProductCategoryRequest {
                Code = categories[1].Code
            };

            context.Setup(x => x.Products).ReturnsEntitySet(products);
            context.Setup(x => x.Categories).ReturnsEntitySet(categories);

            Func <Task> act = async() => await service.UpdateCategoryAsync(categories[0].Id, updateCategory);

            act.Should().Throw <RequestedResourceHasConflictException>();
        }
        public async Task CreateHiveSectio_RequestedResourceHasConflictException(
            [Frozen] Mock <IProductStoreHiveContext> context,
            HiveSectionService service,
            IFixture fixture)
        {
            var hives = fixture.CreateMany <StoreHive>(3).ToArray();

            context.Setup(x => x.Hives).ReturnsEntitySet(hives);
            var sections = fixture.CreateMany <StoreHiveSection>(3).ToList();

            context.Setup(x => x.Sections).ReturnsEntitySet(sections);
            var section = new UpdateHiveSectionRequest {
                Code = sections[0].Code
            };
            Func <Task> act = async() => await service.CreateHiveSectionAsync(section, hives[0].Id);

            act.Should().Throw <RequestedResourceHasConflictException>();
        }
Пример #6
0
        public async Task GetHivesTestAsync([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            IList <StoreHive> hives = fixture.CreateMany <StoreHive>(10).ToList();

            context.Setup(c => c.Hives).ReturnsEntitySet(hives);
            var amount = await service.GetHivesAsync();

            amount.Should().HaveSameCount(hives);
        }
Пример #7
0
        public void GetAllFields_FieldsNumberEqualsFieldsNumberFromGameSettings()
        {
            _fixture.Customizations.Add(
                new RandomNumericSequenceGenerator(0, 9));
            for (int i = 0; i < 20; i++)
            {
                var ship1 = _fixture.CreateMany <Coordinates>(5).ToList();
                var ship2 = _fixture.CreateMany <Coordinates>(4).ToList();
                var ship3 = _fixture.CreateMany <Coordinates>(4).ToList();
                _shipBuilder.Build(Arg.Is <int>(x => x == 4 || x == 5), Arg.Any <IEnumerable <Coordinates> >())
                .Returns(ship1, ship2, ship3);
                _grid.Initialize();

                Dictionary <Coordinates, FieldType> allFields = _grid.GetAllFields();

                allFields.Count.Should().Be((int)Math.Pow(_gameSettings.GridSize, 2));
            }
        }
        public async Task DeleteHiveSection_SetFiveElement_DeleteOne_FourReturned(
            [Frozen] Mock <IProductStoreHiveContext> contex,
            HiveSectionService service,
            IFixture fixture)
        {
            var hiveSections = fixture.CreateMany <StoreHiveSection>(5).ToList();
            var hives        = fixture.CreateMany <StoreHive>(3).ToArray();

            contex.Setup(x => x.Hives).ReturnsEntitySet(hives);
            contex.Setup(x => x.Sections).ReturnsEntitySet(hiveSections);
            await service.SetStatusAsync(hiveSections[0].Id, true);

            await service.DeleteHiveSectionAsync(hiveSections[0].Id);

            var result = await service.GetHiveSectionsAsync();

            result.Count.Should().Be(4);
        }
Пример #9
0
 public void BeforeEach()
 {
     fixture = new Fixture().Customize(new AutoMoqCustomization());
     fixture.Customize <Spot>(c => c
                              .Without(x => x.Region));
     fixture.Customize <Lodgment>(c => c
                                  .Without(x => x.Spot)
                                  .Without(y => y.Bookings)
                                  .Without(y => y.Reviews));
     fixture.Customize <CategorySpot>(c => c
                                      .Without(x => x.Category)
                                      .Without(x => x.Spot));
     moqRepository       = new Mock <ISpotsRepository>(MockBehavior.Strict);
     moqLodgmentsService = new Mock <ILodgmentsService>(MockBehavior.Strict);
     moqStorageService   = new Mock <IStorageService>(MockBehavior.Strict);
     moqReportsService   = new Mock <IReportsService>(MockBehavior.Strict);
     expectedSpot        = fixture.Create <Spot>();
     spot                 = fixture.Create <Spot>();
     spotId               = fixture.Create <int>();
     existSpot            = fixture.Create <Spot>();
     existCategory        = fixture.Create <Category>();
     expectedCategorySpot = fixture.Create <CategorySpot>();
     existRegion          = fixture.Create <Region>();
     region               = fixture.Create <Region>();
     expectedLodgment     = fixture.Create <Lodgment>();
     lodgment             = fixture.Create <Lodgment>();
     expectedLodgments    = fixture.CreateMany <Lodgment>();
     expectedSpots        = fixture.CreateMany <Spot>();
     lodgmentId           = fixture.Create <int>();
     paging               = fixture.Create <PagingModel>();
     lodgmentOptions      = new LodgmentOptionsModel()
     {
         CheckIn          = DateTime.Now.Ticks,
         CheckOut         = DateTime.Now.Ticks + (TimeSpan.TicksPerDay * fixture.Create <int>()),
         AmountOfAdults   = fixture.Create <byte>(),
         AmountOfUnderAge = fixture.Create <byte>(),
         AmountOfBabies   = fixture.Create <byte>()
     };
     expectedPaginatedLodgments = fixture.Create <PaginatedModel <Lodgment> >();
     expectedPaginatedSpots     = fixture.Create <PaginatedModel <Spot> >();
     service = new SpotsService(moqRepository.Object, moqLodgmentsService.Object,
                                moqStorageService.Object, moqReportsService.Object);
     paginatedSpots = fixture.Create <PaginatedModel <Spot> >();
 }
Пример #10
0
            public void Arrange(string applicableProductId, string productId, int numberOfProducts, int x)
            {
                _fixture = new Fixture();

                _fixture.Register(() => new Product(productId, 120.75));

                _products = _fixture.CreateMany <Product>(numberOfProducts).ToList();

                _sut = new XOrMoreProducts(applicableProductId, x, 100.65);
            }
Пример #11
0
        public async Task Setstatus_HasConflictException_Entity_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveService hiveService, int hiveId, bool deletedStatus)
        {
            var listEntity = fixture.CreateMany <StoreHive>(0).ToList();

            context.Setup(c => c.Hives).ReturnsEntitySet(listEntity);
            var ex = await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() =>
                                                                                      hiveService.SetStatusAsync(hiveId, deletedStatus));

            Assert.Equal(typeof(RequestedResourceHasConflictException), ex.GetType());
        }
Пример #12
0
 protected virtual void InnerInit(IFixture fixture)
 {
     Metadatas = fixture.CreateMany <TemplateCodeGenerationMetadata>(5).ToList();
     Metadatas[0].BaseTemplates.Add(Metadatas[1]);
     Metadatas[0].BaseTemplates.Add(Metadatas[2]);
     Metadatas[0].BaseTemplates.Add(Metadatas[3]);
     Metadatas[0].BaseTemplates.Add(Metadatas[4]);
     Metadata = Metadatas[0];
     _init    = true;
 }
Пример #13
0
        public async Task CreateHiveTestAsync([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            IList <StoreHive> hives = fixture.CreateMany <StoreHive>(10).ToList();

            context.Setup(c => c.Hives).ReturnsEntitySet(hives);
            var createRequest = fixture.Create <UpdateHiveRequest>();
            var newHive       = service.CreateHiveAsync(createRequest).Result;

            Assert.NotNull(newHive);
        }
Пример #14
0
        public async Task DeleteHiveTestAsync_WithWrongStatus_ThrowsException([Frozen] Mock <IProductStoreHiveContext> context, HiveService service, IFixture fixture)
        {
            var hiveId = 1;
            var hives  = fixture.CreateMany <StoreHive>(1).ToList();

            hives[0].Id        = hiveId;
            hives[0].IsDeleted = false;
            context.Setup(s => s.Hives).ReturnsEntitySet(hives);
            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(() => service.DeleteHiveAsync(hiveId));
        }
Пример #15
0
 public static void CustomizeMetadata(this IFixture fixture)
 {
     fixture.Customize <Metadata>(customization =>
                                  customization.FromFactory <int>(value =>
                                                                  fixture
                                                                  .CreateMany <KeyValuePair <MetadataKey, string> >(new Random(value).Next(1, 5))
                                                                  .Aggregate(Metadata.None,
                                                                             (data, metadatum) => data.Add(metadatum))
                                                                  ));
 }
Пример #16
0
            public void Arrange(string applicableProductId, string productId, int numberOfProducts, int x, int y)
            {
                _fixture = new Fixture();

                _fixture.Register(() => new Product(productId, 100.55));

                _products = _fixture.CreateMany <Product>(numberOfProducts).ToList();

                _sut = new XForYFreeProducts(applicableProductId, x, y);
            }
Пример #17
0
        public object Create(object request, ISpecimenContext context)
        {
            var info = request as ParameterInfo;

            if (info == null || info.ParameterType != typeof(FieldList) || info.Name != "fields")
            {
                return(new NoSpecimen());
            }

            var           list   = new FieldList();
            List <ID>     ids    = _fixture.CreateMany <ID>().ToList();
            List <string> values = _fixture.CreateMany <string>("value").ToList();

            for (int i = 0; i < ids.Count; i++)
            {
                list.Add(ids[i], values[i]);
            }
            return(list);
        }
        public async Task SetStatusAsync_HiveSection_RequestedResourceNotFoundException(IFixture fixture)
        {
            var storeSectionHives = fixture.CreateMany <StoreHiveSection>(0).ToArray();

            _context.Setup(s => s.Sections).ReturnsEntitySet(storeSectionHives);

            var service = new HiveSectionService(_context.Object, _userContext.Object);

            await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => service.SetStatusAsync(1, true));
        }
Пример #19
0
        public async Task GetProductCategory_NotFound_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCategoryService productCategoryService, int productCategoeyId)
        {
            var listEntity = fixture.CreateMany <ProductCategory>(0).ToList();

            context.Setup(c => c.Categories).ReturnsEntitySet(listEntity);

            var ex = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => productCategoryService.GetCategoryAsync(productCategoeyId));

            Assert.Equal(typeof(RequestedResourceNotFoundException), ex.GetType());
        }
        private CsvUploadRecord CreateRandomAddressBaseRecord(string gazetteer)
        {
            var singleAddressLine = string.Join(',', _fixture.CreateMany <string>(4));
            var gss_code          = gazetteer == "local" ? _hackneyGssCode : "E06281728";

            return(_fixture.Build <CsvUploadRecord>()
                   .With(c => c.gss_code, gss_code)
                   .With(a => a.single_line_address, singleAddressLine)
                   .Create());
        }
            public void Arrange(string applicableProductId, string productId)
            {
                _fixture = new Fixture();

                _fixture.Register(() => new Product(productId, 120.75));

                _products = _fixture.CreateMany <Product>().ToList();

                _sut = new DiscountPerProduct(applicableProductId, 100.65);
            }
        public void Init()
        {
            var arraySize  = 6;
            var entitySize = Marshal.SizeOf(typeof(PayloadEvent));

            _expectedValues = _fixture.CreateMany <PayloadEvent>(arraySize).ToArray();
            _generatedFile  = Path.Combine(Directory.GetCurrentDirectory(), _fixture.Create <string>() + ".bin");
            WriteDataToFile(_generatedFile, entitySize, _expectedValues);
            _dataProvider = new MMFDataProvider(_generatedFile, entitySize);
        }
Пример #23
0
        public async Task TrailerListVM_SuccessfulTrailerListFilter()
        {
            base.ClearAll();

            _fixture.Register <IReachability>(() => Mock.Of <IReachability>(r => r.IsConnected() == true));

            var trailers = _fixture.CreateMany <Trailer>();

            _trailerRepository.Setup(vr => vr.GetAllAsync()).ReturnsAsync(trailers);

            var vm = _fixture.Create <TrailerListViewModel>();
            await vm.Init();

            vm.TrailerSearchText = trailers.First().Registration;

            Assert.Equal(1, vm.Trailers.ToList().Count);

            Assert.Equal(trailers.First(), vm.Trailers.First().Trailer);
        }
Пример #24
0
        public async Task UpdateHiveAsync_PassesHiveIdAndUpdateHiveRequest_ExpectsRequestedResourceHasConflictException(
            [Frozen] Mock <IProductStoreHiveContext> contextMock,
            HiveService hiveService,
            IFixture fixture)
        {
            string code              = "12345";
            var    storeHives        = fixture.CreateMany <StoreHive>(3).ToList();
            var    storeHiveSections = fixture.CreateMany <StoreHiveSection>(3).ToList();

            contextMock.Setup(c => c.Hives).ReturnsEntitySet(storeHives);
            contextMock.Setup(c => c.Sections).ReturnsEntitySet(storeHiveSections);
            storeHives[0].Code = code;
            var createRequest = new UpdateHiveRequest {
                Address = "Kuprevicha 1-1", Code = code, Name = "qwerty"
            };

            await Assert.ThrowsAsync <RequestedResourceHasConflictException>(
                () => hiveService.UpdateHiveAsync(1, createRequest));
        }
Пример #25
0
        public void SetUp()
        {
            _fixture         = new Fixture();
            _customerService = new Mock <ICustomerService>();

            _customerService.Setup(x => x.GetAllCustomers())
            .Returns(_fixture.CreateMany <CustomerModel>(5));

            _target = new MainPageViewModel(_customerService.Object);
        }
        public void GetAmount_SetWithTwoElements_TwoReturned([Frozen] Mock <ICustomerContext> context, CustomerManagementService service, IFixture fixture)
        {
            var customers = fixture.CreateMany <Customer>(10).ToArray();

            context.Setup(c => c.Customers).ReturnsEntitySet(customers);

            var amount = service.GetAmount();

            amount.Should().Be(customers.Length);
        }
Пример #27
0
        public async Task GetHiveSection_NotFound_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService, int hiveSectionHiveId)
        {
            var listEntity = fixture.CreateMany <StoreHiveSection>(0).ToList();

            context.Setup(c => c.Sections).ReturnsEntitySet(listEntity);

            var ex = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => hiveSectionService.GetHiveSectionAsync(hiveSectionHiveId));

            Assert.Equal(typeof(RequestedResourceNotFoundException), ex.GetType());
        }
Пример #28
0
        public async Task DeleteHiveSection_NotFoundException_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService, int hiveSectionId)
        {
            var listEntity    = fixture.CreateMany <StoreHiveSection>(13).ToList();
            var createRequest = fixture.Create <UpdateHiveSectionRequest>();

            context.Setup(x => x.Sections).ReturnsEntitySet(listEntity);
            var ex = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => hiveSectionService.UpdeteHiveSectionAsync(hiveSectionId, createRequest));

            Assert.Equal(typeof(RequestedResourceNotFoundException), ex.GetType());
        }
Пример #29
0
        public async Task GetHiveSections_Test([Frozen] Mock <IProductStoreHiveContext> context, IFixture fixture, HiveSectionService hiveSectionService)
        {
            var listSectionEntity = fixture.CreateMany <StoreHiveSection>(13).ToList();

            context.Setup(c => c.Sections).ReturnsEntitySet(listSectionEntity);

            var hiveSections = await hiveSectionService.GetHiveSectionsAsync();

            Assert.Equal(13, hiveSections.Count);
        }
        public async Task DeleteProduct_NotFoundException_Test([Frozen] Mock <IProductCatalogueContext> context, IFixture fixture, ProductCatalogueService productCatalogueService, int productCatalogId)
        {
            var listEntity    = fixture.CreateMany <CatalogueProduct>(13).ToList();
            var createRequest = fixture.Create <UpdateProductRequest>();

            context.Setup(x => x.Products).ReturnsEntitySet(listEntity);
            var ex = await Assert.ThrowsAsync <RequestedResourceNotFoundException>(() => productCatalogueService.UpdateProductAsync(productCatalogId, createRequest));

            Assert.Equal(typeof(RequestedResourceNotFoundException), ex.GetType());
        }
Пример #31
0
        public void Is_the_sum_of_composed_claims(IFixture fixture)
        {
            var xs = fixture.CreateMany <int>(6).OrderBy(i => i).ToArray();
            var ys = fixture.CreateMany <int>(6).OrderBy(i => i).ToArray();

            var a = (topLeft : (x : xs[1], y : ys[0]), bottomRight : (x : xs[4], y : ys[5]));
            var b = (topLeft : (x : xs[2], y : ys[1]), bottomRight : (x : xs[5], y : ys[3]));
            var c = (topLeft : (x : xs[0], y : ys[2]), bottomRight : (x : xs[3], y : ys[4]));

            var claimA = new Claim(fixture.Create <int>(), a.topLeft, a.bottomRight);
            var claimB = new Claim(fixture.Create <int>(), b.topLeft, b.bottomRight);
            var claimC = new Claim(fixture.Create <int>(), c.topLeft, c.bottomRight);

            var union = new UnionClaim(claimA, claimB, claimC);

            var X = (x : fixture.CreateRandomBetween(b.topLeft.x, c.bottomRight.x - 1),
                     y : fixture.CreateRandomBetween(c.topLeft.y, b.bottomRight.y - 1));
            var Y = (x : fixture.CreateRandomBetween(a.topLeft.x, b.topLeft.x - 1),
                     y : fixture.CreateRandomBetween(b.bottomRight.y, c.bottomRight.y - 1));
            var Z = (x : fixture.CreateRandomBetween(0, a.topLeft.x - 1),
                     y : fixture.CreateRandomBetween(0, c.topLeft.y - 1));

            using (new AssertionScope())
            {
                union[X.x, X.y].Should().Be(3,
                                            "because it is where 3 claims overlap" + FixtureToDebugString(X.x, X.y));
                union[Y.x, Y.y].Should().Be(2,
                                            "because it is where 2 claims overlap" + FixtureToDebugString(Y.x, Y.y));
                union[Z.x, Z.y].Should().Be(0,
                                            "because it is where no claims overlap" + FixtureToDebugString(Z.x, Z.y));
            }

            string FixtureToDebugString(int x, int y)
            {
                return
                    ($" (x: {x}, y: {y}," +
                     $" A: {claimA.XOffset}, {claimA.YOffset}, {claimA.Width}, {claimA.Height}," +
                     $" B: {claimB.XOffset}, {claimB.YOffset}, {claimB.Width}, {claimB.Height}," +
                     $" C: {claimC.XOffset}, {claimC.YOffset}, {claimC.Width}, {claimC.Height})" +
                     union.ToDebugString((x, y)));
            }
        }
        public void RandomOrderIsUsedToChooseNextTest(int count, int randomValue, [Frozen] IRandomizer randomizer, ParadigmTestClassCommand sut, IFixture fixture)
        {
            Mock.Get(randomizer).Setup(x => x.Next(count)).Returns(randomValue);

            var methods = fixture.CreateMany<IMethodInfo>(count).ToList();

            var actual = sut.ChooseNextTest(methods);
            Assert.Equal(randomValue, actual);
        }