|
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Linq; |
| 3 | +using System.Threading.Tasks; |
| 4 | +using Pipedrive.Models.Request; |
| 5 | +using Xunit; |
| 6 | + |
| 7 | +namespace Pipedrive.Tests.Integration.Clients |
| 8 | +{ |
| 9 | + public class ProductsClientTests |
| 10 | + { |
| 11 | + public class TheGetAllMethod |
| 12 | + { |
| 13 | + [IntegrationTest] |
| 14 | + public async Task ReturnsCorrectCountWithoutStart() |
| 15 | + { |
| 16 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 17 | + |
| 18 | + var options = new ProductFilters |
| 19 | + { |
| 20 | + PageSize = 3, |
| 21 | + PageCount = 1 |
| 22 | + }; |
| 23 | + |
| 24 | + var products = await pipedrive.Product.GetAll(options); |
| 25 | + Assert.Equal(3, products.Count); |
| 26 | + } |
| 27 | + |
| 28 | + [IntegrationTest] |
| 29 | + public async Task ReturnsCorrectCountWithStart() |
| 30 | + { |
| 31 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 32 | + |
| 33 | + var options = new ProductFilters |
| 34 | + { |
| 35 | + PageSize = 2, |
| 36 | + PageCount = 1, |
| 37 | + StartPage = 1 |
| 38 | + }; |
| 39 | + |
| 40 | + var products = await pipedrive.Product.GetAll(options); |
| 41 | + Assert.Equal(2, products.Count); |
| 42 | + } |
| 43 | + |
| 44 | + [IntegrationTest] |
| 45 | + public async Task ReturnsDistinctInfosBasedOnStartPage() |
| 46 | + { |
| 47 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 48 | + |
| 49 | + var startOptions = new ProductFilters |
| 50 | + { |
| 51 | + PageSize = 1, |
| 52 | + PageCount = 1 |
| 53 | + }; |
| 54 | + |
| 55 | + var firstPage = await pipedrive.Product.GetAll(startOptions); |
| 56 | + |
| 57 | + var skipStartOptions = new ProductFilters |
| 58 | + { |
| 59 | + PageSize = 1, |
| 60 | + PageCount = 1, |
| 61 | + StartPage = 1 |
| 62 | + }; |
| 63 | + |
| 64 | + var secondPage = await pipedrive.Product.GetAll(skipStartOptions); |
| 65 | + |
| 66 | + Assert.NotEqual(firstPage[0].Id, secondPage[0].Id); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + public class TheGetByNameMethod |
| 71 | + { |
| 72 | + [IntegrationTest] |
| 73 | + public async Task CanRetrieveProductsByName() |
| 74 | + { |
| 75 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 76 | + |
| 77 | + var products = await pipedrive.Product.GetByName("productname", "GBP"); |
| 78 | + |
| 79 | + Assert.True(products.Count == 1); |
| 80 | + Assert.Equal(12.32M, products[0].Price); |
| 81 | + } |
| 82 | + } |
| 83 | + |
| 84 | + public class TheGetMethod |
| 85 | + { |
| 86 | + [IntegrationTest] |
| 87 | + public async Task CanRetrieveProduct() |
| 88 | + { |
| 89 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 90 | + |
| 91 | + var product = await pipedrive.Product.Get(2); |
| 92 | + |
| 93 | + Assert.Equal("productname", product.Name); |
| 94 | + } |
| 95 | + } |
| 96 | + |
| 97 | + public class TheGetDealsForProductMethod |
| 98 | + { |
| 99 | + [IntegrationTest] |
| 100 | + public async Task CanRetrieveDeals() |
| 101 | + { |
| 102 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 103 | + |
| 104 | + var deals = await pipedrive.Product.GetDealsForProduct(2); |
| 105 | + |
| 106 | + Assert.Equal(1, deals.Count); |
| 107 | + } |
| 108 | + } |
| 109 | + |
| 110 | + public class TheGetFilesForProductMethod |
| 111 | + { |
| 112 | + [IntegrationTest] |
| 113 | + public async Task ReturnsCorrectCount() |
| 114 | + { |
| 115 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 116 | + |
| 117 | + var files = await pipedrive.Product.GetFilesForProduct(1); |
| 118 | + |
| 119 | + Assert.Equal(1, files.Count); |
| 120 | + } |
| 121 | + } |
| 122 | + |
| 123 | + public class TheGetFollowersForProductMethod |
| 124 | + { |
| 125 | + [IntegrationTest] |
| 126 | + public async Task ReturnsCorrectCount() |
| 127 | + { |
| 128 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 129 | + |
| 130 | + var followers = await pipedrive.Product.GetFollowersForProduct(1); |
| 131 | + |
| 132 | + Assert.Equal(1, followers.Count); |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + public class TheGetPermittedUsersMethod |
| 137 | + { |
| 138 | + [IntegrationTest] |
| 139 | + public async Task ReturnsCorrectCount() |
| 140 | + { |
| 141 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 142 | + |
| 143 | + var permittedUsers = await pipedrive.Product.GetPermittedUsers(2); |
| 144 | + |
| 145 | + Assert.Equal(2, permittedUsers.Count); |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + public class TheCreateMethod |
| 150 | + { |
| 151 | + [IntegrationTest] |
| 152 | + public async Task CanCreate() |
| 153 | + { |
| 154 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 155 | + var fixture = pipedrive.Product; |
| 156 | + |
| 157 | + var newProduct = new NewProduct("New Product Name") |
| 158 | + { |
| 159 | + Prices = new List<NewProductPrice> { new NewProductPrice { Currency = "GBP", Price = 10.23M } } |
| 160 | + }; |
| 161 | + |
| 162 | + var product = await fixture.Create(newProduct); |
| 163 | + Assert.NotNull(product); |
| 164 | + |
| 165 | + var retrieved = await fixture.Get(product.Id); |
| 166 | + Assert.NotNull(retrieved); |
| 167 | + Assert.Equal("GBP", retrieved.Prices.First().Currency); |
| 168 | + Assert.Equal(10.23M, retrieved.Prices.First().Price); |
| 169 | + |
| 170 | + // Cleanup |
| 171 | + await fixture.Delete(product.Id); |
| 172 | + } |
| 173 | + } |
| 174 | + |
| 175 | + public class TheEditMethod |
| 176 | + { |
| 177 | + [IntegrationTest] |
| 178 | + public async Task CanEdit() |
| 179 | + { |
| 180 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 181 | + var fixture = pipedrive.Product; |
| 182 | + |
| 183 | + var newProduct = new NewProduct("product") |
| 184 | + { |
| 185 | + Prices = new List<NewProductPrice> { new NewProductPrice { Currency = "GBP", Price = 10.23M } } |
| 186 | + }; |
| 187 | + var product = await fixture.Create(newProduct); |
| 188 | + |
| 189 | + var editedProduct = product.ToUpdate(); |
| 190 | + editedProduct.Name = "updated-name"; |
| 191 | + editedProduct.Prices.First(x => x.Currency == "GBP").Price = 20.50M; |
| 192 | + |
| 193 | + var updatedProduct = await fixture.Edit(product.Id, editedProduct); |
| 194 | + |
| 195 | + Assert.Equal("updated-name", updatedProduct.Name); |
| 196 | + Assert.Equal(20.50M, updatedProduct.Prices["GBP"].Price); |
| 197 | + |
| 198 | + // Cleanup |
| 199 | + await fixture.Delete(updatedProduct.Id); |
| 200 | + } |
| 201 | + } |
| 202 | + |
| 203 | + public class TheDeleteMethod |
| 204 | + { |
| 205 | + [IntegrationTest] |
| 206 | + public async Task CanDelete() |
| 207 | + { |
| 208 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 209 | + var fixture = pipedrive.Product; |
| 210 | + |
| 211 | + var newProduct = new NewProduct("new-name"); |
| 212 | + var product = await fixture.Create(newProduct); |
| 213 | + |
| 214 | + var createdProduct = await fixture.Get(product.Id); |
| 215 | + |
| 216 | + Assert.NotNull(createdProduct); |
| 217 | + |
| 218 | + await fixture.Delete(createdProduct.Id); |
| 219 | + |
| 220 | + var deletedProduct = await fixture.Get(createdProduct.Id); |
| 221 | + Assert.False(deletedProduct.ActiveFlag); |
| 222 | + } |
| 223 | + } |
| 224 | + |
| 225 | + public class TheAddFollowerMethod |
| 226 | + { |
| 227 | + [IntegrationTest] |
| 228 | + public async Task CanAddFollower() |
| 229 | + { |
| 230 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 231 | + var fixture = pipedrive.Product; |
| 232 | + |
| 233 | + var addFollower = await fixture.AddFollower(1, 9953182); |
| 234 | + Assert.NotNull(addFollower); |
| 235 | + } |
| 236 | + } |
| 237 | + |
| 238 | + public class TheDeleteFollowerMethod |
| 239 | + { |
| 240 | + [IntegrationTest] |
| 241 | + public async Task CanDeleteFollower() |
| 242 | + { |
| 243 | + var pipedrive = Helper.GetAuthenticatedClient(); |
| 244 | + var fixture = pipedrive.Product; |
| 245 | + |
| 246 | + await fixture.DeleteFollower(1, 1); |
| 247 | + } |
| 248 | + } |
| 249 | + } |
| 250 | +} |
0 commit comments