public async Task CatBySecondaryId_ForSecondaryId_Successful()
        {
            var cat         = Cats.FirstOrDefault();
            var existingCat = await CatRepository.GetBySecondaryId(cat.SecondaryId);

            existingCat.Name.Should().Be(cat.Name);
        }
        public async Task Should_Contain_Specific_Cat()
        {
            var cat  = Cats.FirstOrDefault();
            var cats = await CatRepository.GetAllAsync();

            cats.FirstOrDefault(x => x.Name == cat.Name).Should().NotBeNull();
        }
        public async Task GetAll_SpecificCatExists_Successful()
        {
            var cat  = Cats.FirstOrDefault();
            var cats = await CatRepository.GetAll();

            cats.FirstOrDefault(x => x.Name == cat.Name).Should().NotBeNull();
        }
        public async Task Should_Get_Cat_By_Id()
        {
            var cat         = Cats.FirstOrDefault();
            var existingCat = await CatRepository.GetByIdAsync(cat.Id);

            existingCat.Name.Should().Be(cat.Name);
        }
        public async Task Delete_Cat_Successful()
        {
            var cat = Cats.FirstOrDefault();

            await CatController.Delete(cat.Id);

            Cats.FirstOrDefault(x => x.Id == cat.Id).Should().BeNull();
        }
Beispiel #6
0
        public void Delete_Cat_Successful()
        {
            var cat = Cats.FirstOrDefault();;

            ViewModel.SelectedCat = cat;
            ViewModel.Delete();

            Cats.FirstOrDefault(x => x.Id == cat.Id).Should().BeNull();
        }
        public async Task Update_Cat_Successful()
        {
            var cat     = Cats.FirstOrDefault();
            var newName = Guid.NewGuid().ToString();

            cat.Name = newName;

            await CatController.Put(cat);

            Cats.FirstOrDefault(x => x.Name == newName).Should().NotBeNull();
        }
        public async Task Create_Cat_Successful()
        {
            var cat = new Cat()
            {
                Id = Guid.NewGuid(), Name = Guid.NewGuid().ToString()
            };

            await CatController.Post(cat);

            Cats.FirstOrDefault(x => x.Id == cat.Id).Should().BeEquivalentTo(cat);
        }
        public async Task Update_Cat_Successful()
        {
            var cat = Cats.FirstOrDefault();

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

            await CatRepository.Update(cat);

            var existingCat = await CatRepository.GetById(cat.Id);

            existingCat.Id.Should().Be(cat.Id);
        }
Beispiel #10
0
        public void Save_ExistingCat_Successful()
        {
            var cat     = Cats.FirstOrDefault();
            var newName = Guid.NewGuid().ToString();

            cat.Name = newName;

            ViewModel.SelectedCat = cat;
            ViewModel.Save();

            Cats.FirstOrDefault(x => x.Name == newName).Should().NotBeNull();
        }
Beispiel #11
0
        public void Save_NewCat_Successful()
        {
            var cat = new Cat()
            {
                Id = Guid.NewGuid(), Name = Guid.NewGuid().ToString()
            };

            ViewModel.Create();
            ViewModel.SelectedCat = cat;
            ViewModel.Save();

            Cats.FirstOrDefault(x => x.Id == cat.Id).Should().BeEquivalentTo(cat);
        }
        public async Task Save_Should_Write_To_File()
        {
            var tempFile   = GetTemporaryFile();
            var repository = new CatDataRepository(new Settings(tempFile));

            await repository.SaveAsync(Cats);

            var contents = File.ReadAllText(tempFile);

            contents.Should().Contain($"\"Name\":\"{Cats.FirstOrDefault().Name}\"");

            File.Delete(tempFile);
        }
        public async Task Should_Delete_A_Cat()
        {
            var cat = Cats.FirstOrDefault();

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

            await CatRepository.DeleteAsync(cat);

            Cats.Remove(cat);

            var existingCat = await CatRepository.GetByIdAsync(cat.Id);

            existingCat.Should().BeNull();
        }
        public void OneTimeSetUp()
        {
            Setup.Bootstrap(SetupType.Test);

            CreateCatTestData();

            var mockApiClient  = new Mock <IApiClient>();
            var mockServiceBus = new Mock <IMessageBroker <Cat> >();
            var mockCatService = new Mock <ICatService>();

            // Setup the cat service
            mockCatService.Setup(x => x.GetAll()).Returns(Task.FromResult(Cats.AsEnumerable()));

            mockCatService.Setup(x => x.GetById(It.IsAny <Guid>()))
            .Returns((Guid id) => { return(Task.FromResult(Cats.FirstOrDefault(x => x.Id == id))); });

            mockCatService.Setup(x => x.Create(It.IsAny <Cat>()))
            .Returns((Cat entity) =>
            {
                Cats.Add(entity);

                return(Task.CompletedTask);
            });

            mockCatService.Setup(x => x.Update(It.IsAny <Cat>()))
            .Returns((Cat entity) =>
            {
                var existing = Cats.Find(x => x.Id == entity.Id);

                Cats.Remove(existing);
                Cats.Add(entity);

                return(Task.CompletedTask);
            });

            mockCatService.Setup(x => x.Delete(It.IsAny <Guid>()))
            .Returns((Guid id) =>
            {
                Cats.Remove(Cats.FirstOrDefault(x => x.Id == id));
                return(Task.CompletedTask);
            });

            ApiClient     = mockApiClient.Object;
            MessageBroker = mockServiceBus.Object;
            CatService    = mockCatService.Object;

            ViewModel = new MainViewModel(CatService);
        }